Having problem with subclass

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Oct 1 11:21:24 CEST 2010


On Thu, 30 Sep 2010 18:54:00 -0700, tekion wrote:

> When I move  Bclass to A.py, it works.  Is there some restriction in
> python that sub classing a class has be in the same file as the class
> you're are sub classing? Thanks.

Others have already solved your main problem (you need to refer to 
A.Aclass rather than just Aclass), but I'd like to make another comment.

Unlike Java, Python programmers rarely see the need to have one class per 
file, especially if they are small classes. Generally subclasses will be 
small -- you might only change a handful of methods. I'd even go say as 
to say that the Java (anti-)pattern of placing each and every class into 
its own file is actively frowned upon by Python programmers.

By all means arrange your classes into separate modules if that is the 
most natural way to arrange them, but don't artificially break apart 
related classes into separate modules.



-- 
Steven



More information about the Python-list mailing list