On 8/14/07, Barry Warsaw <[EMAIL PROTECTED]> wrote: > It would have been perfect, I think, if I could have opened the file > in text mode so that read() gave me strings, with universal newlines > and preservation of line endings (i.e. no translation to \n).
You can do that already, by passing newline="\n" to the open() function when using text mode. Try this script for a demo: f = open("@", "wb") f.write("bare nl\n" "crlf\r\n" "bare nl\n" "crlf\r\n") f.close() f = open("@", "r") # default, universal newlines mode print(f.readlines()) f.close() f = open("@", "r", newline="\n") # recognize only \n as newline print(f.readlines()) f.close() This outputs: ['bare nl\n', 'crlf\n', 'bare nl\n', 'crlf\n'] ['bare nl\n', 'crlf\r\n', 'bare nl\n', 'crlf\r\n'] Now, this doesn't support bare \r as line terminator, but I doubt you care much about that (unless you want to port the email package to Mac OS 9 :-). -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com