Newbie Q: dynamically assigning object attribute

Ben Wilson dausha at gmail.com
Fri Feb 10 14:17:11 EST 2006


Well, my Perl way of doing it would be to have all attributes in a dict
(hash), then create the accessor vi a dynamic function. I knew Python
would have a right way to do it for Python, but when I went looking I
neglected to look at the core of the language. I suppose I'm just too
accustomed to the TIMTOWTDY approach to expect the
one-ring-to-bind-them-all solution. :-) It's a mental shift on my part,
to be certain.

What I was actually doing was reading a user configuration file and
setting an object's variables--the example I got was a fairly close
approximation of how I was trying to approach it before setattr().

Thanks,
Ben




More information about the Python-list mailing list