I have a class as follows:
class Hand():
def __init__(self, hand_a, play_deck, split_count, name): # hand_a for hand actual
self.hand_a = hand_a # the actual hand when instance created
self.play_deck = play_deck # need to move this to deck class
self.split_count = split_count
self.name = name
In another class I create an instance of Hand:
class DECK():
def __init__(self):
pass
def deal(self, play_deck):
dhand = {}
phand = {}
for i in range (2):
play_deck, phand[i] = pick_item(play_deck)
play_deck, dhand[i] = pick_item(play_deck)
# creat instance of Hand for player's starting hand
self.start_hand = Hand(phand, play_deck, 0, "Player 1")
In a third class I’m trying to access my first instance of Hand called ‘start_hand’:
class Game():
def __init__(self):
pass
def play_game(self):
self.deck = DECK()
self.deck.deal(play_deck)
print "dhand = %r" % start_hand.hand_a
But I get the following error:
print "dhand = %r" % start_hand.hand_a
NameError: global name 'start_hand' is not defined
I’ve also tried:
print "dhand = %r" % self.start_hand.hand_a
but I get the following error:
print "dhand = %r" % self.start_hand.hand_a
AttributeError: Game instance has no attribute 'start_hand'
Do I have to create the class instance in some other way, or do I have to access it differently or both? Or am I just so way off that I should start over?
Your
start_handis a member ofdeckobject.