I'm a newbie and I'm having a really strange (like in the title, for me) problem. This is the code:
from random import shuffle
class Carta:
listaSemi=[" ","Bastoni","Spade","Coppe","Denari"]
listaValori=[" ","Asso","Due","Tre","Quattro",
"Cinque","Sei","Sette","Otto","Nove","Dieci"]
def __init__(self,seme,valore):
self.seme=seme
self.valore=valore
def __str__(self):
s1=self.listaValori[self.valore]
s2=self.listaSemi[self.seme]
return " ".join((s1,"di",s2))
class Mazzo:
def __init__(self):
self.Carte=[]
def Crea(self):
for seme in range(1,5):
for valore in range(1,11):
self.Carte.append(Carta(seme, valore))
def Mescola(self):
shuffle(self.Carte)
When i do:
M=Mazzo
Mazzo.Crea(M)
I get:
Traceback (most recent call last):
File "<pyshell#62>", line 1, in <module>
Mazzo.Crea(M)
File "/home/administrator/Scrivania/Script/Carte.py", line 19, in Crea
self.Carte.append(Carta(seme, valore))
AttributeError: type object 'Mazzo' has no attribute 'Carte'
Thanks in advance for your help!
Mto be an instance ofMazzo? Then doM=Mazzo()with parenthesis. OtherwiseMis just a reference to the classMazzoandMazzo.Crea(M)just meansMazzo.Crea(Mazzo). OnceMis an instance ofMazzo,Mazzo.Crea(M)can also be writtenM.Crea().M.Crea()andM = Mazzo()? Also yourCrea()method takes no parameter, soMazzo.Crea(M)is syntactically incorrect.