What I\'m trying to do:
I\'m trying to change the formatting on a csv file from space delimited to comma delimited.
What I\'ve don
The wording is just a bit vague. The file should be opened with newline=''
, but newline
is not a valid option for csv.writer()
itself.
To avoid this error , open the file in 'wb'
mode instead of 'w'
mode. This will eliminate the need for newline.
Corrected code is as follows:
with open(csvpath, 'wb') as g:
gWriter = csv.writer(g)
gWriter.writerows(rows)
The following will do
with open('filename_inCSV.csv',mode='r') as csvfile:
or
with open('filename_inCSV.csv','r') as csvfile:
newline
does not work in with open('output.csv', 'a',newline='') as fp
. It will return back an error:
'newline' is an invalid keyword argument for this function
I used 'ab'
method and it worked without blank lines between the lines:
with open('output.csv', 'ab',) as fp