[issue4847] csv fails when file is opened in binary mode

2009-01-05 Thread jaywalker

jaywalker  added the comment:

In an unlikely scenario:
say one of the fields has an embedded \r. For instance "blahblah\r" is the 
value of the first column. Now open this file in text mode. What happens to 
this '\r' even before csv.reader sees it? If it remains intact, no problem. If 
it is converted to a newline in any platform, and that newline is not exactly 
\r, does this not introduce a problem?

Just curious...

Thanks.

- Original Message 
From: STINNER Victor 
To: jaywal...@yahoo.com
Sent: Monday, January 5, 2009 12:05:59 PM
Subject: [issue4847] csv fails when file is opened in binary mode

STINNER Victor  added the comment:

Do you expect to be able to read CSV as bytes or just to fix the 
documentation example?

--
nosy: +haypo

___
Python tracker 
<http://bugs.python.org/issue4847>
___

___
Python tracker 
<http://bugs.python.org/issue4847>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4847] csv fails when file is opened in binary mode

2009-01-05 Thread jaywalker

jaywalker  added the comment:

make it '\r\n', if you want. Such files can be easily generated on windows text 
editors, or even linux ones nowadays. Upon reading, if the file is opened in 
text mode, this will probably be converted to \n even on linux by python (I may 
be wrong). Thus, \r gets lost.

Not a biggie, but you never know ;0)

- Original Message 
From: STINNER Victor 
To: jaywal...@yahoo.com
Sent: Monday, January 5, 2009 12:23:45 PM
Subject: [issue4847] csv fails when file is opened in binary mode

STINNER Victor  added the comment:

> say one of the fields has an embedded \r. For instance "blahblah\r" is the
> value of the first column. Now open this file in text mode. What happens to
> this '\r' even before csv.reader sees it?

I used rarely the CSV format, but it sounds strange to have a newline 
character in a column. Newlines characters (\r and \n) are reserved to mark 
the end of the line. Can you produce such file to test? :-)

I guess that the csv modules does something like readline().split(";").

___
Python tracker 
<http://bugs.python.org/issue4847>
___

___
Python tracker 
<http://bugs.python.org/issue4847>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4847] csv fails when file is opened in binary mode

2009-01-05 Thread jaywalker

jaywalker  added the comment:

I think what you suggest makes most sense. 
Thanks.

- Original Message 
From: Antoine Pitrou 
To: jaywal...@yahoo.com
Sent: Monday, January 5, 2009 12:47:21 PM
Subject: [issue4847] csv fails when file is opened in binary mode

Antoine Pitrou  added the comment:

You can avoid the newline translation problem by using the newline
parameter in open(). Set it to '' (the empty string) and any CR and LF
characters should remain intact.

As for the original problem, IMHO it is a documentation bug.

--
assignee:  -> georg.brandl
components: +Documentation -Library (Lib)
nosy: +georg.brandl, pitrou
priority:  -> normal

___
Python tracker 
<http://bugs.python.org/issue4847>
___

___
Python tracker 
<http://bugs.python.org/issue4847>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4847] csv fails when file is opened in binary mode

2009-01-05 Thread jaywalker

New submission from jaywalker :

The following code from the documentation fails:
#
import csv
reader = csv.reader(open("eggs.csv", "rb"))
for row in reader:
print(row)
#
The output is:
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in 
_csv.Error: iterator should return strings, not bytes (did you open the
file in text mode?)


It works as expected in python 2.6

--
components: Library (Lib)
messages: 79165
nosy: jaywalker
severity: normal
status: open
title: csv fails when file is opened in binary mode
versions: Python 3.0

___
Python tracker 
<http://bugs.python.org/issue4847>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com