Cursed newlines and readline()
Skip Montanaro
skip at pobox.com
Thu Sep 12 15:55:05 EDT 2002
Edward> According to one of Leo's Linux users, the Python's readline()
Edward> routine on Linux delivers "\r\n" line end strings verbatim,
Edward> while the windows versions force the string to use the Unix
Edward> convention of using only "\n".
In 2.3 you can open files with the "U" flag and get "universal newline"
support:
% python
Python 2.3a0 (#86, Sep 4 2002, 21:13:00)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open("crlf.txt")
>>> line = f.readline()
>>> line
'This is an example of what I have come to call the "cursed newline" problem,\r\n'
>>> f = open("crlf.txt", "rU")
>>> line = f.readline()
>>> line
'This is an example of what I have come to call the "cursed newline" problem,\n'
--
Skip Montanaro
skip at pobox.com
consulting: http://manatee.mojam.com/~skip/resume.html
More information about the Python-list
mailing list