[Tutor] csv module not raising exception properly

David Rock david at graniteweb.com
Thu Apr 7 20:54:23 CEST 2005


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


Shouldn't I be able to catch this? The reason I'm doing it this way is
because I have discovered a ctrl-M in the data I am parsing and the csv
module bombs out on it. I needed to check each line individually. I
thought I could do a try block around the csv.reader line and deal with
the rare exception.

Does anyone know why this try block doesn't catch the exception? The
version of Python I am using is 2.3.3

Thanks.

-- 
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/50eb16a9/attachment.pgp


More information about the Tutor mailing list