Hello everyone !
I am a still a beginner in Python (and have no knowledge in other languages), and today I got a reaction from my script that I find unexpected.
Here's the code:
I want to use the buildOneCard function to create a card (a couple of values), by using datas stock in a dictionnary in another function (here, frenchCard).
class Card:
"""
Define the different kinds of play card.
A card is constituted of several elements (usually two) that reflect its
value.
These elements are tuples
"""
def __init__(self):
"Nothing here yet"
def frenchCard(self):
"""
Define a card like the ones used in poker. Return a dictionnary.
elements = the dictionnary used to handle data
rank = The rank of the card (main value discriminant)
color = The color order is taken in account when the ranks are equal
"""
return {'rank' : (2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace'),
'color' : ('Spade', 'Club', 'Diamond', 'Heart')}
def buildOneCard(self, card_type=''):
"Will hopefully build a card when given a type of card"
self.card_type = card_type
for elements in getattr(self, '%s' % card_type)():
print elements
When I launch it in the shell, it returns rank and color... and nothing else !
If I replace print with return, it says that elements is not defined !
And I am pretty clueless, so if someone can explain it to me, thanks in advance !