module not callable - why not?

Hung Jung Lu hungjunglu at yahoo.com
Mon Apr 19 13:08:41 EDT 2004


aahz at pythoncraft.com (Aahz) wrote in message news:<c5ultg$ss9$1 at panix2.panix.com>...
> In article <8ef9bea6.0404180956.cd1a152 at posting.google.com>,
> Hung Jung Lu <hungjunglu at yahoo.com> wrote:
> >
> >(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')

You can't do this when you are inside the module itself. Similarly,
unless I am inside a class, I wouldn't use getattr(self, 'name'). I
was comparing apple to apple. You gave me an orange. :)

Hung Jung



More information about the Python-list mailing list