class variable: def __init__(self) : self.data = {} self.sub = [] def __getitem__(self,idx) : if idx in self.data : return self.data[idx] else : return def __setitem__(self,idx,value) : self.data[idx] = value def __str__(self) : b=[] b.append(str(self.data)) if len(self.sub)>0 : b.append("(") for i in self.sub : b.append(str(i)) b.append(")") return " ".join(b) def __call__(self,arg) : return self.sub[arg] def __add__(self,other) : self.sub.append(other) return self def test(self) : print(str(self)) v = variable() v[1] = 100 v[2] = 200 t = v v += variable() v(0)[1]=100 v(0)["a"]="aab" t += variable() v(1)[1]=100 t += variable() v(2)[1]=100 print( v[1]) print( v[2]) print( v[3]) print(v) print(v(0)) t = v.test t()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question