attrdict and namedtuple moved to lib

--HG--
branch : sandbox
This commit is contained in:
Andreas
2009-10-22 19:51:09 +00:00
parent 0acda95080
commit 67375bd6e3
4 changed files with 21 additions and 33 deletions

20
lib/attrdict.py Normal file
View File

@@ -0,0 +1,20 @@
# 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))