Unexpected behavior of universal newline mode with StringIO and csv modules
问题 Consider the following (Python 3.2 under Windows): >>> import io >>> import csv >>> output = io.StringIO() # default parameter newline=None >>> csvdata = [1, 'a', 'Whoa!\nNewlines!'] >>> writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC) >>> writer.writerow(csvdata) 25 >>> output.getvalue() '1,"a","Whoa!\nNewlines!"\r\n' Why is there a single \n - shouldn't it have been converted to \r\n since universal newlines mode is enabled? With this enabled, on input , the lines endings \n , \r ,