import CardDeck
from CardDeck import player
from CardDeck import deck
from CardDeck import hand
game_deck=deck()
def create_new_deck():
global game_deck
game_deck=deck()
game_deck.shuffle(100)
print "Creating new Deck...."
I would like for the create_new_deck()
function to create a completely new instance of a deck object and use the old game_deck
reference to refer to this new object. However, what happens is that python just calls the __init__()
function again on the old instance of the object reffered to by game_deck
.
How do I create a new instance of a class using an old variable name in Python?
The deck class looks like this
class deck(object):
cardList=[]
#creates 52 card deck
def __init__(self):
print "*******creating new deck*******"
for i in range(1,14):
self.cardList.append(card("spade",i))
print "*******creating spades*******"
for i in range(1,14):
self.cardList.append(card("heart",i))
print "*******creating hearts*******"
for i in range(1,14):
self.cardList.append(card("diamond",i))
print "*******creating diamonds*******"
for i in range(1,14):
self.cardList.append(card("club",i))
print "*******creating clubs*******"