getattr/setattr q.

Steven Bethard steven.bethard at gmail.com
Tue Apr 3 12:38:41 EDT 2007


Steve Holden wrote:
> You don't need setattr/getattr if you know in advance the name of the 
> attribute you need to access and you can get a reference to the object 
> whose attribute it is. So:
> 
>  >>> x = "Hello, Paulo"
>  >>> import sys
>  >>> sys.modules['__main__'].x
> 'Hello, Paulo'

a.k.a

     >>> import __main__
     >>> __main__.x
     'Hello, Paulo'

STeVe



More information about the Python-list mailing list