readling newlines

John Roth newsgroups at jhrothjr.com
Sun Jan 11 16:12:20 EST 2004


"Alessandro Crugnola *sephiroth*" <alessandro at sephiroth.it> wrote in message
news:IXTLb.87546$_P.3280883 at news4.tin.it...
> Hi, I'm trying to detect the newlines method of a file opened.
> I'm using the 'U' mode as parameter when opening a file, but for every
file opened the result is always "\r\n", even if the file has
> been saved with the "\n" newline method.
> Is there i'm missing?
>
> I'm on Windows with python 2.3.3

Regardless of what you tell it, Python will always write a text
file with the operating system's line separators. In Windows,
that's \r\n. Universal newline mode only operates on input,
and will translate *all* common system's line separators into
/n.

In other words, if you write a file in text mode using /n, and
then read it back in binary mode, you'll see /r/n for the line
separators. Universal newline support does not change this
because it does not change what you see in binary mode.

John Roth
>
>





More information about the Python-list mailing list