basic python questions

Diez B. Roggisch deets at nospam.web.de
Sat Nov 18 18:30:09 CET 2006


nateastle at gmail.com schrieb:
> I have taken the coments and think I have implemented most. My only

Unfortunately, no.

> question is how to use the enumerator. Here is what I did, I have tried
> a couple of things but was unable to figure out how to get the line
> number.
> 
> def Xref(filename):
>     try:
>         fp = open(filename, "r")
>     except:
>         raise "Couldn't read input file \"%s\"" % filename

You still got that I-catch-all-except in there.
This will produce subtle bugs when you e.g. misspell a variable name:

filename = '/tmp/foo'
try:
    f = open(fliename, 'r')
except:
    raise "can't open filename"


Please notice the wrong-spelled 'fliename'.

This OTOH will give you more clues on what really goes wrong:



filename = '/tmp/foo'
try:
    f = open(fliename, 'r')
except IOError:
    raise "can't open filename"


Diez



More information about the Python-list mailing list