classification
Title: csv writer with blank lineterminator breaks quoting
Type: behavior Stage:
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Eric.Haszlakiewicz, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2014-11-12 17:05 by Eric.Haszlakiewicz, last changed 2014-11-12 17:37 by r.david.murray.

Messages (3)
msg231083 - (view) Author: Eric Haszlakiewicz (Eric.Haszlakiewicz) Date: 2014-11-12 17:05
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:
    col1,"col2
    data",col3

It should be possible to change the lineterminator without changing the quoting behavior.
At the very least, the documentation needs to explain better what logic is used to determine whether something gets quoted, and what affects that.
msg231086 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-11-12 17:31
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.)
msg231088 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-11-12 17:37
Also, it is hard to see how to make this clearer:

csv.QUOTE_MINIMAL
Instructs writer objects to only quote those fields which contain special characters such as delimiter, quotechar or any of the characters in lineterminator.

Hmm.  Perhaps it would be a bit clearer if it said "... which contain the special characters delimiter, quotechar, ..."
History
Date User Action Args
2014-11-12 17:37:50r.david.murraysetversions: + Python 3.4, Python 3.5
2014-11-12 17:37:39r.david.murraysetstatus: closed -> open

assignee: docs@python
components: + Documentation, - Library (Lib)

nosy: + docs@python
messages: + msg231088
resolution: not a bug ->
stage: resolved ->
2014-11-12 17:31:12r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg231086

resolution: not a bug
stage: resolved
2014-11-12 17:05:03Eric.Haszlakiewiczcreate