Re: Second python program: classes, sorting

2008-08-11 Thread Bruno Desthuilliers
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

Re: Second python program: classes, sorting

2008-08-11 Thread Eric Brunel
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

Re: Second python program: classes, sorting

2008-08-10 Thread Peter Otten
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

Re: Second python program: classes, sorting

2008-08-10 Thread Wojtek Walczak
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

Re: Second python program: classes, sorting

2008-08-10 Thread B
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

Re: Second python program: classes, sorting

2008-08-10 Thread WP
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

Second python program: classes, sorting

2008-08-10 Thread WP
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