when does newlines get set in universal newlines mode?

arekfu at gmail.com arekfu at gmail.com
Mon May 4 05:50:35 EDT 2015


Hi all,

I have a text file with Windows-style line terminators (\r\n) which I open in universal newlines mode (Python 2.7). I would expect the newlines attribute to be set after the first call to the readline() method, but apparently this is not the case:

>>> f=open('test_crlf', 'rU')
>>> f.newlines
>>> f.readline()
'foo\n'
>>> f.newlines
>>> f.readline()
'bar\n'
>>> f.newlines
'\r\n'
On the other hand, the newlines attribute gets set after the first call to readline() on a file with Unix-style line endings.

Is this a bug or a feature?

Thanks in advance,
Davide



More information about the Python-list mailing list