Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import functools
  2.  
  3. class MTuple:
  4.     def __init__(self, t):
  5.         self.tuple = tuple(t)
  6.    
  7.     def __neg__(self):
  8.         l = list(self.tuple.__iter__())
  9.         l.reverse()
  10.         return MTuple(l)
  11.    
  12.     def func(self, method = None, *args):
  13.         for i in range(len(args)):
  14.             if isinstance(args[i], MTuple):
  15.                 args[i] = args[i].tuple
  16.         res = getattr(self, method)(args)
  17.         if type(res) == type(tuple):
  18.             return MTuple(res)
  19.         else:
  20.             return res
  21.        
  22.     def __getattr__(self, attr):
  23.         return functools.partial(self.func, method = attr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement