In a blackjack game I have the following piece of code:
class Hand(object): def __init__(self): self.hand =  def hand_score(self): ... class Dealer(object): def __init__(self): Hand.__init__(self)
hand_score() should calculate the score in
self.hand and return it’s value. However when I assign
dealer = Dealer(), deal the cards and call
dealer.hand_score() it gives me the error
AttributeError: 'Dealer' object has no attribute 'hand_score'.
self.hand value is inherited and works as expected when I call
You aren’t actually inheriting from
Hand; you are just inappropriately using
Hand.__init__ to initialize an unrelated instance.
Hand has to be listed as a base class in the class definition.
class Dealer(Hand): def __init__(self): Hand.__init__(self) # preferably, super().__init__()