Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo(object):
- a = None
- b = None
- def __init__(self, b=None):
- self.a = 'A'
- self.b = b
- def return_ab(self):
- return self.a, self.b
- def return_child(self):
- return Bar()
- class Bar(Foo):
- def example_method(self):
- print self.return_ab()
- foo = Foo('B')
- print foo.a # A
- print foo.b # B
- print foo.return_ab() # ('A', 'B')
- foo.return_child().example_method()
- # ('A', None)
- # Why does B not have a value when called from the child class, and how can this be rectified?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement