Apr-05-2017, 08:25 PM
Hi,
I have a list as follows stored in a variable name csvImport:
[['3-March-17', 'a', 'b', 'c'],
['16-February-17', 'd', 'e', 'f'],
['19-January-17', 'g', 'h', 'i']]
I use the following code to write to a csv file.
So when I read the created csv file back to Python, the list would look like this:
[['3-March-17', 'a', 'b', 'c'],
[]
['16-February-17', 'd', 'e', 'f'],
[]
['19-January-17', 'g', 'h', 'i']]
What can I do to prevent new rows being added when I write a list to a csv file?
Thank you!
I have a list as follows stored in a variable name csvImport:
[['3-March-17', 'a', 'b', 'c'],
['16-February-17', 'd', 'e', 'f'],
['19-January-17', 'g', 'h', 'i']]
I use the following code to write to a csv file.
with open(r"C:\folder\myFile.csv", "w") as csvFile: writer = csv.writer(csvFile, delimiter=",") for item in csvImport: writer.writerow(item)However, when I use the code to write it to a csv file, and I opened the csv file with Excel, it seems to add an additional row in between the original rows of data.
So when I read the created csv file back to Python, the list would look like this:
[['3-March-17', 'a', 'b', 'c'],
[]
['16-February-17', 'd', 'e', 'f'],
[]
['19-January-17', 'g', 'h', 'i']]
What can I do to prevent new rows being added when I write a list to a csv file?
Thank you!