On 2013-09-04 16:31, MRAB wrote: > You could try replacing the '\r' with another character that doesn't > appear elsewhere and then change it back afterwards. > > MARKER = '\x01' > > def cr_to_marker(f): > for line in f: > yield line.replace('\r', MARKER) > > def marker_to_cr(item): > return item.replace(MARKER, '\r') > > f = file('out.txt', 'rb') > r = csv.reader(cr_to_marker(f)) > for i, row in enumerate(r): # works in 2.7, fails in 2.4 > row = [marker_to_cr(item) for item in row] > print repr(row) > f.close()
This works pretty well. I'm not sure if there's a grave performance penalty for mucking with strings so much, but at this point my Care-o-Meter is barely registering, as long as it works. > Which OS are you using? On Windows the lines (rows) end with > '\r\n', so the last item of each row will end with '\r', which > you'll need to strip off. (That would be a problem only if the last > item of a row could end with '\r'.) It's on Win32. -tkc -- https://mail.python.org/mailman/listinfo/python-list