what's the general way of separating classes?

bruno at modulix onurb at xiludom.gro
Mon Mar 20 14:29:17 EST 2006


John Salerno wrote:
> From my brief experience with C#, I learned that it was pretty standard
> practice to put each class in a separate file. I assume this is a
> benefit of a compiled language that the files can then be grouped together.
> 
> What I'm wondering is how is this normally handled in Python? Is it
> normal for classes to be put in separate modules?

Depends on the size of the classes... I tend to write as small as
possible classes, so I usually have a bunch of closely related classes
(and functions and constants...) in a module.

> It seems like this can
> get out of hand, since modules are separate from one another and not
> compiled together. You'd end up with a lot of import statements.

Sorry, but I don't see the correlation between compilation and import
here ?

As for imports, you have to import each needed symbol anyway - from
module import * is really bad practice IMHO, except in the shell, and
then it's just a matter of packaging related modules together (which
should be the case anyway) and setting the __all__ attribute of the
package __init__.

> Are related classes put into a single module then? Or is there some
> recommended method for how to handle this?

cf above. And/or browse the standard lib's sources - you know, it's Open
Source !-)

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