Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################
- # foobar.py
- x = 10
- class _Foobar:
- @property
- def y(self):
- global x
- return x + 32
- import sys
- _ref, sys.modules[__name__] = sys.modules[__name__], _Foobar()
- ########################
- # test_foobar.py
- import foobar
- # Use existing module property.
- print(foobar.y) # -> 42
- # Dynamically add a property to the module.
- foobar.a = 3
- foobar.__class__.b = property(lambda self: self.a + 1)
- print(foobar.b) # -> 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement