programmatically calling a function

Carl Banks invalidemail at
Sat Mar 5 20:17:55 CET 2005

Doug Schwarz wrote:
> I don't see how getattr solves the original problem.  What, exactly,
> the first argument to getattr?

mod = __import__(__this__)
f = getattr(mod,"foo")

I tend to prefer this over globals() because it seems a little less
magical to me, especially when setting a global.  Either this or
gloabls() will work fine.  Please don't use eval for stuff like this:
that's not what it's for and it has the potential to be dangerous.


More information about the Python-list mailing list