WP a écrit :
Hello, here are some new things I've problems with. I've made a program
that opens and reads a text file. Each line in the file contains a name
and a score. I'm assuming the file has the correct format. Each
name-score pair is used to instantiate a class Score I've written. This
w
Others have replied to your original question. As an aside, just a few
stylistic notes:
class Score:
def __init__(self, name_, score_):
self.name = name_
self.score = score_
These trailing underscores look like a habit from another language. They
are unneeded in Pyth
WP wrote:
> I solved it, I rewrote __cmp__ to:
> def __cmp__(self, other):
> if self.score == other.score:
> return cmp(self.name, other.name)
> else:
> return cmp(other.score, self.score)
You can simplify that to
def __cmp__(self, other):
return cmp(other.score, self.s
Dnia Sun, 10 Aug 2008 20:26:51 +0200, WP napisa�(a):
Hi,
> Hello, here are some new things I've problems with. I've made a program
...
> def __cmp__(self, other):
> print "in __cmp__"
> return self.score >= other.score
Check this out: http://docs.python.org/ref/customiza
WP wrote:
Hello, here are some new things I've problems with. I've made a program
that opens and reads a text file. Each line in the file contains a name
and a score. I'm assuming the file has the correct format. Each
name-score pair is used to instantiate a class Score I've written. This
work
WP wrote:
Solved the problem, see below...
Hello, here are some new things I've problems with. I've made a program
that opens and reads a text file. Each line in the file contains a name
and a score. I'm assuming the file has the correct format. Each
name-score pair is used to instantiate a cl
Hello, here are some new things I've problems with. I've made a program
that opens and reads a text file. Each line in the file contains a name
and a score. I'm assuming the file has the correct format. Each
name-score pair is used to instantiate a class Score I've written. This
works fine, but