getattr/setattr q.
Steve Holden
steve at holdenweb.com
Tue Apr 3 12:43:17 EDT 2007
Steven Bethard wrote:
> 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'
>
Indeed. Any handle on the right object will do.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
More information about the Python-list
mailing list