getattr from local scope

rob.haswell at gmail.com rob.haswell at gmail.com
Sun Apr 23 17:17:30 EDT 2006


Hey there

My question is pretty simple - I want to use something like getattr to
grab a symbol from the local scope from a string.

Basically my application has a scheduler which stores names of
functions
defined in the "schedule" module in a database, to be run on certain
days.
Every night I call schedule.RunSchedule, which grabs all the rows on
the
database that have to be run now, and I want to call the function
defined
the same module according to that string.

I know I can use eval, but I've always been told that if you're using
eval, you're doing it wrong. Also not using eval limits the scope
damage
that can be caused by any errors in my application which could cause
the
database to be poisoned.

Cheers for any help :-)

-Rob




More information about the Python-list mailing list