Tuesday, May 19, 2009

getattr on a script

I wanted to dispatch calls to other functions within my script, but couldn't figure out what object to pass as argument to getattr. Turns out __name__ is the name of my module, and I can look up a reference in sys.modules.

Handy!

REF: getattr on a function - comp.lang.python | Google Groups