package structure prepared

--HG--
branch : aspn
This commit is contained in:
Andreas
2008-02-03 22:11:44 +00:00
parent 7f180c3e1d
commit 15f61db14f
5 changed files with 738 additions and 0 deletions

27
src/bunch.py Normal file
View File

@@ -0,0 +1,27 @@
class Bunch:
def __init__(self, **kwds):
self.__dict__.update(kwds)
# that's it! Now, you can create a Bunch
# whenever you want to group a few variables:
point = Bunch(datum=y, squared=y*y, coord=x)
# and of course you can read/write the named
# attributes you just created, add others, del
# some of them, etc, etc:
if point.squared > threshold:
point.isok = 1
# Even shorter Bunch, Doug Hudgeon, 2001/08/29
class Bunch:
__init__ = lambda self, **kw: setattr(self, '__dict__', kw)
# When python 2.2 permits the above dynamic __dict__ this could be
# be something like:
class Bunch(list):
def __init__(*args, **kw):
self[:] = list(args)
setattr(self, '__dict__', kw)