Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. class Foo(object):
  2.     a = None
  3.     b = None
  4.  
  5.     def __init__(self, b=None):
  6.         self.a = 'A'
  7.         self.b = b
  8.  
  9.     def return_ab(self):
  10.         return self.a, self.b
  11.  
  12.     def return_child(self):
  13.         return Bar()
  14.  
  15.  
  16. class Bar(Foo):
  17.    
  18.     def example_method(self):
  19.         print self.return_ab()    
  20.  
  21. foo = Foo('B')
  22. print foo.a  # A
  23. print foo.b  # B
  24. print foo.return_ab() # ('A', 'B')
  25.  
  26. foo.return_child().example_method()
  27. #  ('A', None)
  28.  
  29. # 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