I've been organizing my python projects starting with package folders.
Say I name my package "foo", foo is the top level folder for the source code. Inside foo there is a "main.py" file as the project's start point, and other various modules, let's have one called "module1.py". Now, add another package under "foo", the obvious example name here would be "bar", and add another module under "bar" called "module2.py".
The project structure looks like this:
- foo/
|- main.py
|- module1.py
|- bar/
|- module2.py
To reference "module1.py" in "module2.py", just write
import foo.module1
To reference "module2.py" in "main.py", do as follows
import foo.bar.module2
There is no problem importing from any level.
To start the program from command line, enter:
python -m foo.main
Say I name my package "foo", foo is the top level folder for the source code. Inside foo there is a "main.py" file as the project's start point, and other various modules, let's have one called "module1.py". Now, add another package under "foo", the obvious example name here would be "bar", and add another module under "bar" called "module2.py".
The project structure looks like this:
To reference "module1.py" in "module2.py", just write To reference "module2.py" in "main.py", do as follows There is no problem importing from any level.To start the program from command line, enter:
python -m foo.main