Cool object trick

Steven Bethard steven.bethard at
Fri Dec 17 18:18:46 CET 2004

Robert Brewer wrote:
> Alex Stapleton wrote:
>>you can't do
>>var = "varA"
>>obj = struct(varA = "Hello")
>>print obj.var
>>and expect it to say Hello to you.
> Did you mean "print obj.varA"?

I believe he meant that he wanted the equivalent of:

getattr(obj, var)


More information about the Python-list mailing list