I’m looking into organizing my modules and classes. All the time I collect my related classes in a relevant module so I can do things like:
from vehicles.car import engine
In directory vehicles there is a file named car which contains class engine. Clear.
Now I’m looking into the possibility that I can store a class in a file. So I can do something like:
from filters import air
and the air class is a file on its own. However it’s not clear to me how I can have a class named air which is stored into its own file called air.py
If filters.py contained all my classes then this import would work, but that’s not what I want.
Any tips or pointers?
Create a directory called
filters, and filesfilters/__init__.pyandfilters/air.py.In
filters/__init__.py, have:from air import air, and infilters/air.py, define the classair.Then: