Files
py_sandbox/lib/attrdict.py
Andreas 67375bd6e3 attrdict and namedtuple moved to lib
--HG--
branch : sandbox
2009-10-22 19:51:09 +00:00

21 lines
556 B
Python

# Copyright (c) 2009 Andreas Balogh
# See LICENSE for details.
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):
ch = AttrDict(self)
return ch
def __repr__(self):
return 'AttrDict(' + dict.__repr__(self) + ')'
@classmethod
def fromkeys(cls, seq, value = None):
return AttrDict(dict.fromkeys(seq, value))