Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import inspect
- def private(method):
- def func(self, *args, **kwargs):
- print("Private method call")
- outer_frame = inspect.stack()[1][0]
- if 'self' not in outer_frame.f_locals or outer_frame.f_locals['self'] is not args[0]:
- raise Exception('Call to a private method outside!!!')
- method(self)
- return func
- class Some:
- def foo(self):
- print("Foo!")
- def bar(self):
- print("Bar!")
- self.baz(self)
- @private
- def baz(self):
- print("Baz!")
- some = Some()
- some.foo()
- some.bar()
- some.baz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement