script question
python at bdurham.com
python at bdurham.com
Fri Apr 17 14:08:54 EDT 2009
Scott,
Newbie question (and I'm not the OP): What are your thoughts on having
your decorator add an attribute to the functions vs. placing the
functions in a global variable?
def _included(f):
f._included = True
return f
I tried experimenting with this technique, but could not find a way to
use dir() to discover all my functions with an _included attribute.
The following convoluted comprehension works to execute functions with
an _included attribute when a list of function names is available.
[ eval(x)() for x in [ 'func01', 'func02', 'func03' ] if getattr(
eval(x), '_included', False ) ]
However, I can't figure out a way to replace my list of hard-coded
function names with the output from the dir() command.
Thank you for your thoughts,
Malcolm
More information about the Python-list
mailing list