Advertisement
_cronos2

Python classes

Sep 5th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from functools import wraps
  4.  
  5. def self_wrapper(meth):
  6.  
  7.     @wraps(meth)
  8.     def wrapper(self_instance):
  9.         return meth(self_instance._i)
  10.  
  11.     return wrapper
  12.  
  13. class B:
  14.     def __init__(self, instance):
  15.         self._i = instance
  16.  
  17.     @self_wrapper
  18.     def f(self):
  19.         return self.x
  20.  
  21. class A:
  22.     x = 5
  23.    
  24.     def __init__(self):
  25.         self.b = B(self)
  26.  
  27. a = A()
  28. print a.b.f()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement