Sorting a list of class instances
Gerson Kurz
gerson.kurz at t-online.de
Wed Dec 25 12:50:39 EST 2002
On Wed, 25 Dec 2002 17:29:11 GMT, "Grant Ito" <Grant_Ito at shaw.ca>
wrote:
>class Deck(list):
> def __init__(self, numCards):
> self = []
> for i in range(numCards):
> self.append(Card(i))
The stmt "self = []" is reassigning the variable "self". "self" is not
a keyword like "this" in python, its just a convention.
What you want to do is: initialize the list class (the
"list.__init__(self)" in the example below) instead:
class Deck(list):
def __init__(self, numCards):
list.__init__(self) # <-------- initialize list baseclass
for i in range(numCards):
self.append(Card(i))
More information about the Python-list
mailing list