Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A(object):
- pass
- class B(A):
- def __add__(self, other):
- return self.value + other
- a = A()
- a.value = 5
- a.__class__ = B
- print a + 10
- a = A() # parent class
- b = B() # subclass
- b.value = 3 # random setting of values
- a.__dict__ = b.__dict__ # give object a b's values
- # now proceed to use object a
- import copy
- a.__dict__ = copy.deepcopy(b.__dict__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement