Python Style Question

Greg Fortune lists at gregfortune.com
Mon May 19 17:18:27 EDT 2003


Lothar Scholz wrote:

> In the python windows library i find a lot of code like the following:
> 
> 
> TypeBrowseDialog_Parent=dialog.Dialog
> class TypeBrowseDialog(TypeBrowseDialog_Parent):
> "Browse a type library"
> 
> 
> where is here the advantage over the easier and much more normal way
> to
> do things:
> 
> 
> class TypeBrowseDialog(dialog.Dialog):
> "Browse a type library"
> 
> 
> When i look at the code i must not go through an extra indirection to
> recognize what is done there and more important the first code style
> can't be handled by static code analysers very well.

Looks like the coder expected a performance improvement.  If it gets 
executed the way I expect, the second example requires a lookup through the 
dialog module each time the class is instantiated.  The first only requires 
the lookup when the module loads and binds the results of the lookup into 
the module namespace.  If the class is getting instantiated many, many 
times, the performace increase might be noticable.  You might try replacing 
one of those class in the win32 library (one that you would expect to get 
instatiated often) with the simpler code and see if you notice a slowdown...

Greg Fortune
Fortune Solutions





More information about the Python-list mailing list