I have a question related to Python file management. The way how I organize my Python files are as follows (__init__.py
is empty):
--src
|---__init__.py
|---module1
| |----- __init__.py
| |----- my_file1.py
|---module2
| |----- __init__.py
| |----- my_file2.py
--app
|---my_application.py
As you can see, I separate my codes into two groups: the first group of codes, which is located in src
directory, contains self-defined library codes; the second group of codes, which is located in app
directory, contains the application codes that will call the self-defined library. my_application.py
may contain the following codes:
from src.module1.my_file1 import ClassA1, ClassA2, ClassA3
from src.module2.my_file2 import ClassB1, ClassB2, ClassB3
a = ClassA1()
b = ClassB3()
It is boring to import classes from self-defined library whenever I write an application based on it. I would like to have something like that:
Request 1:
import all classes defined in src.module1
Request 2:
import fundamental classes defined in src.module1 and src.module2
Here fundamental classes may refer to
ClassA1
insrc.module1.my_file1
andClassB2
insrc.module2.my_file2
In C++, this can be realized very easily. For example, for the second requirement, I can put all the header files that are related to fundamental classes in one head file. Then in the application program, I just include this head file. But I have no ideas how Python can work. Thanks.