I'm trying to create a list of class objects, but if I for example run something like this:
for i in range(7)
The list will still be formed of just None-type objects in the end.
If I try to do that without the alist=[None]*7, I get an index out of range error.
So, how is this done exactly? Is it even possible? Or is there another way to do it?
The final goal is to create a magic the gathering-like open source clone.
The part of the code that doesn't work looks something like this:
for i in range(self.n):
for j in range(tempcard.nc-1):
for i in range(9):
if self.cards[i]==None :
print 'smth is wrong'
And guess what? It prints 'smth is wrong' 9 times... (yes there are 3 cards in the txt file, each should be inserted 3 times in the deck, and it seems to read correctly from the file).
And if I try to do something like print self.cards.nc it says the "None" class has no nc attribute.
The card class is also sort of strange. It looks like this:
def __init__(self, filename,tbfilename):
Reads from file all the abilities of the card.
Saves them in class variables.
self.img = None
Loads the image of the card
print "Loading image "+self.filename
self.tb = image.load("./data/"+self.tbfilename)
Draws the card at given x,y coordinates
Any ideas what I could do to make it work? Or another solution how I could do this?
Thanks for your time. Any suggestion is welcomed.