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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to