[Tutor] csv module not raising exception properly

David Rock david at graniteweb.com
Thu Apr 7 22:00:47 CEST 2005


* Kent Johnson <kent37 at tds.net> [2005-04-07 15:28]:
> David Rock wrote:
> >I am trying to catch an exception from the csv module but it doesn't
> >seem to be generating a proper exception because I don't seem to be able
> >to catch it. Here is what I am doing:
> >
> >
> >for inputline in fileinput.input(args):
> >	try:
> >		input = csv.reader([inputline], escapechar='\\')
> >	except:
> >		print "ERROR", inputline
> >
> >
> >This is the traceback:
> >Traceback (most recent call last):
> >  File "/usr/openv/local/bin/bpdbreport_test.py", line 539, in ?
> >    for line in input:
> >_csv.Error: newline inside string
> 
> I'm suspicious of this - the traceback doesn't match the code you show. Is 
> your program called bpdbreport_test.py? What is happening at line 539 of 
> bpdbreport_test.py?

Line 539 is the csv.reader line. I just boiled it down to the place
where things don't make sense. I use try/except blocks all the time and
I even tested this one by putting a "raise" statement inside the block
and it picked it up, so it's not a scope issue or anything weird like
that. I think the csv module doesn't raise an exception properly. Can
someone verify that it works for them?

I am going to continue testing with an extremely watered down version to
see if it _ever_ works right.

-- 
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050407/f1943cc7/attachment.pgp


More information about the Tutor mailing list