pre-PEP generic objects
Steven Bethard
steven.bethard at gmail.com
Fri Dec 3 18:28:01 EST 2004
Ian Bicking wrote:
> class bunch(object):
> def __init__(self, **kw):
> for name, value in kw.items():
> # IMPORTANT! This is subclass friendly: updating __dict__
> # is not!
> setattr(self, name, value)
Good point about being subclass friendly... I wonder if there's an easy
way of doing what update does though... Update (and therefore __init__)
allows you to pass in a Bunch, dict, (key, value) sequence or keyword
arguments by taking advantage of dict's update method. Is there a clean
way of supporting all these variants using setattr?
Steve
More information about the Python-list
mailing list