script question

Peter Otten __peter__ at web.de
Fri Apr 17 22:11:04 CEST 2009


python at bdurham.com wrote:

> For completeness, here is the corrected version of my original code for
> the archives:
> 
> [ eval(x)() for x in dir() if hasattr( eval(x), '_included') ]

Another eval-free variant:

[x() for x in vars().values() if hasattr(x, "_included")]

If you use getattr(x, "_included", False) instead of hasattr() you
can "un-include" functions with 

f._included = False 

instead of 

del f._included

Peter



More information about the Python-list mailing list