Too many imports to use a business class library?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Jul 13 04:04:23 EDT 2006


Sanjay wrote:
> I am new to python. Sorry if this is too novice question,

Don't worry and welcome.


> While coding a business class library, I think it is preferable to have
> one class per source file, rather than combining all classes into one
> file, considering multiple developers developing the classes.

The use of one class = one sourcefile is often coming from Java.
Usually in Python people use something in the middle, putting related
names / functions / classes in the same module.
And you can put related modules in the same directory (with the
__init__ file).


> Is there not a simple solution, a single import and you are able to use
> all the classes? Is there anything wrong in my approcah? Waiting for
> suggestions.

Other things that you may find useful to organize your names and
modules:
- the __all__ list to choose what to export;
- you can import a whole directory of modules;
- you can put many names in the same import line (from xx import xy,
yz, etc).
- Sometimes you can even use from XX import *  but this can be a little
dangerous.

Bye,
bearophile




More information about the Python-list mailing list