script question

python at bdurham.com python at bdurham.com
Fri Apr 17 17:02:19 EDT 2009


Peter,

> 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 ...

YES! That's what I was struggling to do with my in-elegant use of
eval(), eg. replacing eval() to expand dir() strings with a dictionary
of local objects.

Question: why vars() vs. globals()? My tests in IDLE (Python 2.6) show
vars() and globals() returning the same items.

Thanks,
Malcolm



More information about the Python-list mailing list