-
-
Notifications
You must be signed in to change notification settings - Fork 32k
csv writer with blank lineterminator breaks quoting #67044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm trying to emit a single line of csv without any line terminators, but specifying lineterminator=None results in a "lineterminator must be set" error, and setting lineterminator='' results in lack of quotes around certain fields. with open("foo.csv", "wb") as csvfile:
csvw = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL, lineterminator='')
csvw.writerow(["col1","col2\ndata", "col3"]) I expected the contents of the file to be: It should be possible to change the lineterminator without changing the quoting behavior. |
If the line terminator is not \n, there is no reason to quote values with \n in them. (Try your code with lineterminator set to 'd' to see what I mean.) |
Also, it is hard to see how to make this clearer: csv.QUOTE_MINIMAL Hmm. Perhaps it would be a bit clearer if it said "... which contain the special characters delimiter, quotechar, ..." |
Note that |
The reader does not support non-quoted and non-escaped |
…honGH-115741) (cherry picked from commit c688c0f) Co-authored-by: Serhiy Storchaka <[email protected]>
…honGH-115741) (cherry picked from commit c688c0f) Co-authored-by: Serhiy Storchaka <[email protected]>
…-115741) (GH-115867) (cherry picked from commit c688c0f) Co-authored-by: Serhiy Storchaka <[email protected]>
…() (pythonGH-115741) (cherry picked from commit c688c0f) Co-authored-by: Serhiy Storchaka <[email protected]>
…-115741) (GH-115866) (cherry picked from commit c688c0f) Co-authored-by: Serhiy Storchaka <[email protected]>
I think this is expected behaviour. There is certainly a quirk around escaping and quoting. The writer hits
If one sets the quoting policy to be
Unfortunately if one does set a
|
This is expected. Quoting is used if possible. Setting >>> import csv, sys
>>> csvw = csv.writer(sys.stdout, quoting=csv.QUOTE_NONE, lineterminator='', escapechar='\\')
>>> csvw.writerow(["col1","col2\ndata", "col3"])
col1,col2\
data,col320
>>> csvw = csv.writer(sys.stdout, quotechar=None, lineterminator='', escapechar='\\')
>>> csvw.writerow(["col1","col2\ndata", "col3"])
col1,col2\
data,col320 |
@serhiy-storchaka so close this bug as "wont-fix"? |
Actually, it was fixed by #115741 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: