Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. class A(object):
  2. pass
  3.  
  4. class B(A):
  5. def __add__(self, other):
  6. return self.value + other
  7.  
  8.  
  9. a = A()
  10. a.value = 5
  11.  
  12. a.__class__ = B
  13.  
  14. print a + 10
  15.  
  16. a = A() # parent class
  17. b = B() # subclass
  18. b.value = 3 # random setting of values
  19.  
  20. a.__dict__ = b.__dict__ # give object a b's values
  21.  
  22. # now proceed to use object a
  23.  
  24. import copy
  25. a.__dict__ = copy.deepcopy(b.__dict__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement