Bugs item #789519, was opened at 2003-08-16 07:16 Message generated for change (Comment added) made by andrewmcnamara 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: Closed >Resolution: Rejected Priority: 5 Submitted By: Larry Meyn (lmeyn) >Assigned to: Andrew McNamara (andrewmcnamara) 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: Andrew McNamara (andrewmcnamara) Date: 2005-01-13 15:10 Message: Logged In: YES user_id=698599 I'm going to close this issue - we will attempt to improve the documentation, so as to bring this issue to user's awareness, but the supplied iterator needs to return "lines" - on a file using \r, this means using universal newline mode. ---------------------------------------------------------------------- Comment By: Bill Bumgarner (bbum) Date: 2003-08-22 04:02 Message: Logged In: YES user_id=103811 Why doesn't the csv module use the lineterminator for reading files? As it is, the lineterminator appears to be used only for the writing of rows to a file. This, of course, means that csv will quite happily write a file that it cannot subsequently read with the same dialect. ---------------------------------------------------------------------- Comment By: Skip Montanaro (montanaro) Date: 2003-08-22 02: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-22 01: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com