I wish I could access the members by name without quotation marks without creating a separate "type" each time!
struct.py
class Struct(object):
def __init__(self,**kargs):
for key,val in kargs.iteritems():
setattr(self,key,val)
if __name__ == '__main__':
t = Struct(a=10,b=20,c=30)
t.c = "<30>"
print t.a, t.b, t.c
<MARKEDONE:~>
✏ ipy struct.py
10 20 <30>
<MARKEDONE:~>
✏
Maybe there is a better way. I'm a dead programmer, so I forgot a lot.
Recommended Posts