attribut of the current module
Alex Martelli
aleax at aleax.it
Fri Sep 21 03:38:22 EDT 2001
"Oleg Orlov11980884" <orlov at diasoft.ru> wrote in message
news:9oeo0n$28vn$1 at gavrilo.mtu.ru...
> How can i get attribut of the current module?
>
> Ugly way: getattr(__import__(__name__), attribname)
Pretty much the same:
getattr(sys.modules[__name__], attribname)
If you have the attribute name as a string variable,
you won't be able to do much more than getattr in any
case. The only issue left is how to get the current
module object, and sys.modules[__name__] is the normal
approach for that.
A different, simpler approach reaching the same goal:
globals()[attribname]
globals() returns the _dictionary_ of the current
module, so you simply subscript it.
Alex
More information about the Python-list
mailing list