メモ 変数コンテナクラス Var とか Enumとか
collection.py
class Var(object):
def __init__(self,kv=[]):
self.__name__=[]
if kv:
for k,v in kv:
self.__dict__[k]=v
self.__name__.append(k)def __iter__(self):
for k in self.__name__:
if not k.startswith("_"):
yield k
def __repr__(self):
return "\n".join(["{}:{}".format(k,v) for k,v in self.__dict__.items()])
def __getitem__(self,k):
return self.__dict__[k]
def __setitem__(self,k,v):
self.__dict__[k]=v
self.__name__.append(k)
class Enum(Var):
def __init__(self,names):
if isinstance(names,str):
names=names.split(" ")
Var.__init__(self,[(n,i) for i,n in enumerate(names)])
self.__label__={i:n for i,n in enumerate(names)}