Why NOT only one class per file?

Christophe chris.cavalaria at free.fr
Thu Apr 5 12:20:36 CEST 2007


Chris Lasher a écrit :
> A friend of mine with a programming background in Java and Perl places
> each class in its own separate file in . I informed him that keeping
> all related classes together in a single file is more in the Python
> idiom than one file per class. He asked why, and frankly, his valid
> question has me flummoxed.

In Java, you HAVE to place a class in it's own file. That's how the 
language works. But in Java, you do not have to place each class in it's 
own module/package, in fact, it would be bad.

It's the same in Python: you do not want to have one class per 
module/package.

Unfortunately, in Python, a module/package is a file, and in Java, it's 
a directory. Also, Python doesn't really have the notion of a "root 
package/module".




Translation: "import foo; foo.foo()" sucks so avoid having only one 
class per module :)



More information about the Python-list mailing list