Python is not Java. Feel free to put many classes in one file, and then name the file according to the category:
import mypackage.image this_image = image.png(...) that_image = image.jpeg(....)
If your classes are so large that you want them to be in separate files to ease the maintenance burden, that's fine, but you shouldn't hurt your users (or yourself if you use your own package;). Collect your public classes in the __init__ package file (or in the category file, for example, in image ) to represent a fairly flat namespace:
mypackage __init__.py (or image.py ):
from _jpeg import jpeg from _png import png
mypackage _jpeg.py :
class jpeg(...): ...
mypackage _png.py :
class png(...): ...
user code:
# if gathered in __init__ import mypackage this_image = mypackage.png(...) that_image = mypackage.jpeg(...)
or:
# if gathered in image.py from mypackage import image this_image = image.png(...) that_image = image.jpeg(....)
Ethan furman
source share