Gabriel, thanks for your hint. I've managed to create an implementation of an AttrDict passing Gabriels tests.

Any more comments about the pythonicness of this implementation?

class AttrDict(dict):
    """A dict whose items can also be accessed as member variables."""
    def __init__(self, *args, **kwargs):
        dict.__init__(self, *args, **kwargs)
        self.__dict__ = self

    def copy(self):
        return AttrDict(self)

    def __repr__(self):
        return 'AttrDict(' + dict.__repr__(self) + ')'

    @classmethod
    def fromkeys(self, seq, value = None):
        return AttrDict(dict.fromkeys(seq, value))

--
Andreas Balogh
baloand (at) gmail.com
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to