attrdict and namedtuple moved to lib
--HG-- branch : sandbox
This commit is contained in:
20
lib/attrdict.py
Normal file
20
lib/attrdict.py
Normal 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))
|
||||
|
||||
Reference in New Issue
Block a user