del an imported Class at EOF... why?

Steven D'Aprano steven at
Wed Oct 7 00:44:11 CEST 2009

On Tue, 06 Oct 2009 10:56:26 -0700, Ryan wrote:

> Good day all!
> I've just inherited a large amount of python code. After spending some
> time pour through the code, I've noticed that the original developer
> (who is no longer w/ the company) constantly deletes the imported
> classes at the end of the .py file. Why would one want to do such a
> thing?

Too much lead paint in his milk as a small child? *grin*

Possibly out of a (misplaced?) sense of "keeping the namespace clean", or 
a desire to prevent people importing his module and then using the 
classes he imports from elsewhere.

Personally, I think it's just a quirk. There's nothing wrong with doing 
so, but nor is there anything right with it either. If he's worried about 
the presence of an alien class messing up his beautifully designed API, 
that's an aesthetic judgment, and can be (partially) managed by using 
__all__ (a global list of names). But in general, I would prefer to 
manage such namespace issues by saying:

import alienmodule 

class MyClass(alienmodule.AlienClass):

rather than:

from alienmodule import AlienClass

class MyClass(AlienClass):

del AlienClass


More information about the Python-list mailing list