Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- class thing():
- def __init__(self):
- self._stuff = { 'foo', 'bar' }
- @property
- def foo(self):
- return True if sys._getframe().f_code.co_name in self._stuff else False
- @property
- def bar(self):
- return True if sys._getframe().f_code.co_name in self._stuff else False
- @foo.setter
- def foo(self, v):
- if v:
- self._stuff.add(sys._getframe().f_code.co_name)
- else:
- self._stuff.discard(sys._getframe().f_code.co_name)
- @bar.setter
- def bar(self, v):
- if v:
- self._stuff.add(sys._getframe().f_code.co_name)
- else:
- self._stuff.discard(sys._getframe().f_code.co_name)
- def __repr__(self):
- return ', '.join(x for x in self._stuff)
- x = thing()
- print('foo %s, bar %s' % (x.foo, x.bar))
- x.foo = True
- print('foo %s, bar %s' % (x.foo, x.bar))
- x.foo = False
- print('foo %s, bar %s' % (x.foo, x.bar))
- x.bar = False
- print('foo %s, bar %s' % (x.foo, x.bar))
- x.foo = True
- x.bar = True
- print('foo %s, bar %s' % (x.foo, x.bar))
- print(x)
Advertisement
Add Comment
Please, Sign In to add comment