Too many imports to use a business class library?

Bruno Desthuilliers onurb at xiludom.gro
Thu Jul 13 04:15:25 EDT 2006


Sanjay wrote:
> Hi all,
> 
> I am new to python. Sorry if this is too novice question, but I could
> not find an answer yet.
> 
> 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 "multiple developpers" already implies the use of a CVS, so it's a
dubious argument here IMHO. Also, Python is not Java, and doesn't force
you into using classes when other constructs will do (functions, dicts
etc). The organization of the source should be done with the
hi-cohesion/low-coupling rule in mind, ie symbols that are very closely
related should go in a same module.

> So, as per my study of python, a developer using the business class
> library has to write so many imports, one per class. Like:
> 
> from person import Person
> from contact import Contact
> .

As you already noticed, this sucks.

> Is there not a simple solution,

- use a CVS (not necessarily 'the' CVS - subversion is somewhat better,
and there are other options too) to address the multi-developper problem
- put closely related symbols in a same module
- put closely related modules in a same package

> a single import and you are able to use
> all the classes?

Python as packages:
http://docs.python.org/tut/node8.html#SECTION008400000000000000000

> Is there anything wrong in my approcah?

cf above

HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list