Second python program: classes, sorting

Eric Brunel see.signature at no.spam
Mon Aug 11 10:51:02 CEST 2008

Others have replied to your original question. As an aside, just a few  
stylistic notes:

> class Score:
>      def __init__(self, name_, score_):
> = name_
>          self.score = score_

These trailing underscores look like a habit from another language. They  
are unneeded in Python; you can write:
class Score:
      def __init__(self, name, score):
 = name
          self.score = score
That's an advantage of the explicit self: no ambiguity between local  
variables and attributes.

> try:
>      infile = open(filename, "r")
> except IOError, (errno, strerror):
>      print "IOError caught when attempting to open file %s. errno = %d,  
> strerror = %s" % (filename, errno, strerror)
>      exit(1)

This try/except block is unneeded too: what you do with the exception is  
more or less the same as the regular behaviour (print an error message and  
exit), except your error message is far less informative than the default  
one, and printed to stdout instead of stderr. I would remove the entire  
try/except block and just write:
infile = open(filename, "r")

python -c "print ''.join([chr(154 - ord(c)) for c in  

More information about the Python-list mailing list