I have python script that generates CSV file by reading multiple csv files as input. from linux machine i am sending that csv file as an email attachment using mail command. when i open that attached file on window's machine using MS Excel its adding one extra blank line line between each line present in csv. when i open that file in linux using vi editor its fine only four lines are present in csv file. Its more strange when i copy that file using winSCP from linux to window and open in MS Excel file is good no extra blank lines. Is there anything wrong in mail command or my script is not generating correct csv file.
can anybody find something wrong that i am missing in this process.
There are discussions related to the CSV writer behavior with respect to the occurrence of additional new lines. Also, the behavior seems to be different from 2.7 and 3.0 versions.
This link talks about the occurrence of such an issue. However this SO question gives a solution.
As per y understanding it is always good to take control of how newline has to be written by the CSV writer by doing something like
You might be running into trouble with different platform specific line endings.
Windows uses
\r\n
, Macs (before OS X) used\r
, UNIX uses\n
.I suggest to inspect the .csv that causes problems with a hex editor or
hexdump
:(The
0a
in here is a newline (\n
). Windows'\r\n
would be0d 0a
).In order to (testwise) convert files from UNIX to Windows line endings (and vice-versa), you can use the dos2unix / unix2dos tools.