Post tagged: classes

Creating attributes on classes

Programmatic addition of methods.

I've gotten used to manipulating members of Python objects with getattr, setattr etc. But a recent similar problem had me stumped. I had a class that I wanted to create a large number of similar behaving properties on (they would all manipulate an internal dictionary):

>>> f = Foo()
>>> f.contributor = 'xyz' …