I am actually a little confused about making module import generalize. What I got here is a class shape. What I want to do is want to import corresponding file as a module based on some condition. What i'm trying to do is:
In Shape.py
class shape:
def __init__(self, shape_id):
if shape_id == '001':
from shapes import triangle as imported_shape
else:
from shapes import square as imported_shape
In main.py:
from Shape import shape
sqaure = shape('002')
...
The project structure is:
Project
|
Shape.py
main.py
shapes
|
triangle.py
square.py
but that does not seems to work as the import is made void after the __init__ function. Is there any way i can make this type of importing more generalized?
idwhile initialization.