By using t
on non-Posix environments (like MSDOS and MS Windows), the \r\n
sequence is transformed into \n
on input (and the opposite on output). b
(binary mode) performs no such translation.
Presumably the CSV library deals with carriage returns (probably by ignoring them whenever it encounters them).
Edit: just noticed a changed question.
Since .CSV files aren't really intended for human readers, the library can output them with \n
(linefeed (LF) aka newline) separators only. They only real downside would be a MSWindows user opening the file with Notepad: it will display poorly. The CSV library could also output files with \r\n
(CR LF) since most programs defend against MSDOS text file conventions.
Either way, the library can write through b
(binary) mode just fine. It is possible that if opened in t
(text) mode, the line separators would have something slightly odd like \r\n\n
. Probably most CSV file parsers ignore the CR, and recognize LF LF as ending a line and following it with an empty (blank) line, which it also ignores.
The +
is explained in the man page:
w+ Open for reading and writing. The file is created if it does
not exist, otherwise it is truncated. The stream is
positioned at the beginning of the file.
The difference is that w+
allows reading and writing whereas w
only allows writing.