Preamble: This technique can be useful if you have big classes of hundreds lines. If your classes are quite small, you should put them in one single file called tastyfood.py
and you'll get the same behaviour, without folders.
If you want to use a folder to classify your classes, you need to have this folder structure:
tastyfood/
__init__.py
chocolate.py
sweets.py
crisps.py
tuna.py
example.py # example file quoted above
and the __init__.py
can contains import statement to make your life easier:
from chocolate import Chocolate
from sweets import Sweet
# ... import everything you want in the tastyfood namespace
so these examples, which can be found in example.py
, can be valid:
import tastyfood
choco = tastyfood.Chocolate()
from tastyfood import Chocolate
choco = Chocolate()
from tastyfood.chocolate import Chocolate # still works too
choco = Chocolate()