[ python-Bugs-1381476 ] csv.reader endless loop

SourceForge.net noreply at sourceforge.net
Sat Dec 17 18:02:25 CET 2005


Bugs item #1381476, was opened at 2005-12-15 12:04
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1381476&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Christian Harms (wwwingman)
>Assigned to: Andrew McNamara (andrewmcnamara)
Summary: csv.reader endless loop 

Initial Comment:
Hi, 

the csv.reader produce a endless loop, ifan parsing
Error is in the last line of the CSV-File. If you put
an "\r" in the last line, cvs.Error is raised and
StopIteration will lost.

import csv, StringIO
fp = StringIO.StringIO("line1\nline2\rerror")
reader = csv.reader(fp)

while 1:
    try: 
        print reader.next()
    except csv.Error:
        print "Error"
    except StopIteration:
        break

Die Problem is in python 2.3 AND python 2.4. Other
version are not checked.

----------------------------------------------------------------------

>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-12-17 18:02

Message:
Logged In: YES 
user_id=1188172

Let the expert judge.

----------------------------------------------------------------------

Comment By: Thomas Lee (krumms)
Date: 2005-12-17 17:56

Message:
Logged In: YES 
user_id=315535

Actually, the problem may not be a problem with the csv
module at all, it may be a misinterpretation of the API on
the submitters part.


Is there any time a non-fatal csv.Error would/could be
raised? Seems to me that a csv.Error would imply a
StopIteration/break ...

----------------------------------------------------------------------

Comment By: Thomas Lee (krumms)
Date: 2005-12-17 16:17

Message:
Logged In: YES 
user_id=315535

I think this may be fixed in subversion:

tom at vanilla:~/work/python$ svn info
Path: .
URL: http://svn.python.org/projects/python/trunk
Repository UUID: 6015fed2-1504-0410-9fe1-9d1591cc4771
Revision: 41731
Node Kind: directory
Schedule: normal
Last Changed Author: fredrik.lundh
Last Changed Rev: 41729
Last Changed Date: 2005-12-17 18:33:21 +1000 (Sat, 17 Dec 2005)
Properties Last Updated: 2005-12-17 21:44:46 +1000 (Sat, 17
Dec 2005)

tom at vanilla:~/work/python$ python -V
Python 2.4.2
tom at vanilla:~/work/python$ python Sandbox/csv_reader_test.py
['line1']
ERROR: newline inside string
tom at vanilla:~/work/python$ ./python -V
Python 2.5a0
tom at vanilla:~/work/python$ ./python Sandbox/csv_reader_test.py
['line1']
ERROR: new-line character seen in unquoted field - do you
need to open the file in universal-newline mode?



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1381476&group_id=5470


More information about the Python-bugs-list mailing list