python - ^M characters in exported file, converting to newlines -


i exported csv excel parse using python. when opened vimmed csv, noticed 1 line ^m characters newlines should be.

name, value, value2, otherstuff ^m name, value, value2, otherstuff ^m 

i have file parsed such modify values , put string (using 'ru' mode in csvreader). however, string has no newlines. wondering, there way split string on ^m character, or way replace \n?

^m how vim displays windows end-of-line's

the dos2unix command should fix you:

dos2unix my_file.csv 

it's due different eol formats on windows/unix.

on windows, it's \r\n

on unix/linux/mac, it's \n

the ^m vim showing windows cr (carriage return) or \r

the python open command documentation has more information on handling universal newlines: http://docs.python.org/2/library/functions.html#open


Comments