module not callable - why not?

Aahz aahz at pythoncraft.com
Sun Apr 18 15:45:52 EDT 2004


In article <8ef9bea6.0404180956.cd1a152 at posting.google.com>,
Hung Jung Lu <hungjunglu at yahoo.com> wrote:
>One more, I promise I'll stop.
>
>(i) For getting attributes by string names, for attributes of
>instances you do getattr(self, 'name'), for module attributes you do
>globals()['name']. I mention this because every once a month or so a
>newbie would ask how to get module level attributes by name.

That's not the only answer, and it's not the one I use:

    import foo
    getattr(foo, 'name')
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"I used to have a .sig but I found it impossible to please everyone..."  --SFJ



More information about the Python-list mailing list