I have a file called Some.csv which has a field (column) which has values like
1000, 2000, .... 39000.
I wanted only the files with 39000 so I wrote the following python script
import os
import csv
with open('Somenew.csv', 'w') as fw:
writr = csv.writer(fw, delimiter=',')
with open('Some.csv','r') as fr:
reader = csv.reader(fr, delimiter = ',')
for row in reader:
if row[2] == '39000': writr.writerow(row)
Now when this executes on Windows it Somenew.csv looks like this
xxxx, xxxx, 39000, xxxx, xxxx
yyyy, yyyy, 39000, yyyy, yyyy
But when executing on Linux (Ubuntu 14.04LTS) there is no extra newline added.
Is there any reason for this? Is it perhaps because of the compiler?
\r\n
for line endings in text files instead of\n
. The simple fix is to read & write your CSV files as binary files, but there are other options in Python 3. What version of Python are you using?