Interesting things of 'getattr' and 'setattr'

Red Forks redforks at gmail.com
Tue Dec 15 07:19:30 EST 2009


I don't know it is a feature, or implement detail:

>>> class C(object): pass
...
>>> c = C()
>>> setattr(c, ' ', 3)
>>> getattr(c, ' ')
3
>>> setattr(c, 'with blank', 4)
>>> getattr(c, 'with blank')
4

getattr / setattr seems treat any string as attribute name.



More information about the Python-list mailing list