[Tutor] how to read from a txt file
cyresse at gmail.com
Tue Mar 15 05:05:46 CET 2005
Whoops, golden rule - "Never post untested code"
On Mon, 14 Mar 2005 21:05:44 -0500, Kent Johnson <kent37 at tds.net> wrote:
> jrlen balane wrote:
> > ok, i've done what sir Kent just said, my fault...
> > but an error still occurs:
> > Traceback (most recent call last):
> > File "C:\Python23\practices\opentxtprintlngnew.py", line 18, in -toplevel-
> > print process(data)
> > File "C:\Python23\practices\opentxtprintlngnew.py", line 10, in process
> > tempLine = int(line)
> > ValueError: invalid literal for int(): abc
> > isn't this the job of :
> > except TypeError:
> > print "Non numeric character in line", line
> > continue #Breaks, and starts with next line
> Yes, only it should be ValueError instead of TypeError. You can check this interactively:
> >>> int('foo')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> ValueError: invalid literal for int(): foo
> Tutor maillist - Tutor at python.org
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
More information about the Tutor