[Python-bugs-list] [ python-Bugs-789519 ] CSV reader does not parse Mac line endings

SourceForge.net noreply at sourceforge.net
Thu Aug 21 10:01:12 EDT 2003


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

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Larry Meyn (lmeyn)
Assigned to: Skip Montanaro (montanaro)
Summary: CSV reader does not parse Mac line endings

Initial Comment:
#Test code:

import csv
import traceback

class excel_mac(csv.Dialect):
    delimiter = ','
    quotechar = '"'
    doublequote = True
    skipinitialspace = False
    lineterminator = '\r'
    quoting = csv.QUOTE_MINIMAL
csv.register_dialect("excel_mac", excel_mac)

class excel_unix(csv.Dialect):
    delimiter = ','
    quotechar = '"'
    doublequote = True
    skipinitialspace = False
    lineterminator = '\n'
    quoting = csv.QUOTE_MINIMAL
csv.register_dialect("excel_unix", excel_unix)

testdata = range(10)

for dialect in ["excel","excel_unix","excel_mac"]:
	try:
		print '\n Testing dialect "%s"' % dialect
		test = file('test.csv','w')
		writer = csv.writer(test,dialect=dialect)
		for i in range(3):
			writer.writerow(testdata)
		test.close()
		
		test = file('test.csv','r')
		reader = csv.reader(test,dialect=dialect)
		for row in reader:
			print row
	except:
		traceback.print_exc()

#Results
"""
 Testing dialect "excel"
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

 Testing dialect "excel_unix"
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

 Testing dialect "excel_mac"
Traceback (most recent call last):
  File "/Users/lmeyn/Desktop/testcsv.py", line 36, in ?
    print row
Error: newline inside string
"""

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

>Comment By: Skip Montanaro (montanaro)
Date: 2003-08-21 11:01

Message:
Logged In: YES 
user_id=44345

We've been discussing this bug on the csv mailing list.  I suspect
we will make a change to U mode for 2.3.1 and 2.4, though we
have yet to test the proposed change.

Skip


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

Comment By: Larry Meyn (lmeyn)
Date: 2003-08-21 10:44

Message:
Logged In: YES 
user_id=28540

If I open files using the universal, 'U', mode this is not a problem.  
Too bad the 'U' mode is not the default. (I know, there is a lot of 
*nix python code out there that opens binary files as text, and it 
would all break if 'U' were the default.)

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

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



More information about the Python-bugs-list mailing list