Store each class in a separate python file

I organize my modules and classes. All the time I collect related classes in the appropriate module, so I can do things like:

from vehicles.car import engine

There is a file in the directories called car, which contains the class engine. Clear.

Now I am studying the possibility of storing a class in a file. So I can do something like:

from filters import air

and the air class is a file in itself. However, it is not clear to me how I can have a class called air, which is stored in its own file called air.py

If filter.py contains all my classes, then this import will work, but that is not what I want.

Any hints or pointers?

+5
source share
1 answer

filters filters/__init__.py filters/air.py.

filters/__init__.py, : from air import air filters/air.py, air.

:

$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from filters import air
>>> air
<class 'filters.air.air'>
>>> 
+8

All Articles