I am using the newline='' feature in my program to avoid the extra lines being placed between each line being written to a CSV file. This error is odd though... I used it before on a previous rev, and it worked fine. I think the CSV file writing feature has been available since Python 2.3? Here's the error I am getting: Traceback (most recent call last): File "C:\Python\parser\parser.py", line 91, in write_header_to_csv() File "C:\Python\parser\parser.py", line 44, in write_header_to_csv csvfile = open('decodedfile.csv', 'w', newline='') TypeError: 'newline' is an invalid keyword argument for this function At the top of my program, I have the following imports: import sys import binascii import csv
Sorry, my mistake. I thought I was running Python 2.7, but I was running Python 3.1. By the way, is there a solution to the extra lines being written to a CSV file using Python 2.7? Thank you.
On Python 2, I'm guessing you are getting extra CRs on Windows? It looks like you have to open in binary mode there to avoid newline translation. This is documented for the "reader" and "writer" functions.
History
Date
User
Action
Args
2022-04-11 14:58:46
admin
set
github: 74509
2017-05-10 02:16:15
martin.panter
set
messages: +
2017-05-10 00:43:31
BeamPower
set
messages: +
2017-05-09 22:41:48
martin.panter
set
status: open -> closednosy: + martin.pantermessages: + resolution: not a bugstage: resolved