codecs.open on Win32 -- converting my newlines to CR+LF

Philip Semanchuk philip at semanchuk.com
Wed Aug 26 23:04:31 EDT 2009


On Aug 26, 2009, at 10:52 PM, Ryan McGuire wrote:

> I've got a UTF-8 encoded text file from Linux with standard newlines
> ("\n").
>
> I'm reading this file on Win32 with Python 2.6:
>
> codecs.open("whatever.txt","r","utf-8").read()
>
> Inexplicably, all the newlines ("\n") are replaced with CR+LF ("\r
> \n") ... Why?

Try using "rb" instead of "r" for the mode in the call to open().

HTH
Philip




More information about the Python-list mailing list