socek

Untitled

May 12th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. class First(object):
  2.  
  3.     def __init__(self, arg):
  4.         self.arg = arg
  5.  
  6.     def my_arg(self):
  7.         return self.arg
  8.  
  9.  
  10. class Second(First):
  11.  
  12.     def my_arg(self):
  13.         return self.arg + 2
  14.  
  15.  
  16. class Third(Second):
  17.  
  18.     def my_arg(self):
  19.         return super().my_arg() + 4
  20.  
  21. el = Second(1)
  22. assert el.my_arg() == 3
  23. el.__class__ = Third
  24. assert el.my_arg() == 7
Advertisement
Add Comment
Please, Sign In to add comment