class Test(): active_subs = [] def __init__(self, sub=None): Test.get_active_subs() if sub: Test.set_active_subs([sub]) @classmethod def set_active_subs(cls, sub): cls.active_subs.extend(sub) @classmethod def get_active_subs(cls): if not cls.active_subs: print 'setting default values' #logic for collecting available subs here cls.active_subs = ['default_1', 'default_2'] return cls.active_subs t1 = Test() print 'currently active subs t1=', t1.get_active_subs() t2 = Test('set_by_t2') print 'currently active subs t2=', t2.get_active_subs() print 'currently active subs t1=', t1.get_active_subs()
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