Advertisement
jsbueno

Chainnable object wrapper in Python

Mar 29th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. class Chain:
  2.     def __init__(self, obj, root=None):
  3.         self.__obj = obj
  4.     def __getattr__(self, attr):
  5.         val = getattr(self.__obj, attr)
  6.         if callable(val):
  7.             self.__callable = val
  8.             return self
  9.         return val
  10.     def __call__(self, *args, **kw):
  11.         val = self.__callable(*args, **kw)
  12.         if val is None:
  13.             return self
  14.         return val
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement