[Python-Dev] Next version of PEP278 - universal newline support (original) (raw)

Jack Jansen Jack.Jansen@oratrix.com
Thu, 14 Mar 2002 23:26:55 +0100


On donderdag, maart 14, 2002, at 08:54 , Just van Rossum wrote:

Am I the only one who wants universal newlines without a new mode character? Ideally I'd like existing code that works with text files to accept any line ending.

No, I definitely like that too. But there's two problems.

First off, I've written the PEP with the idea of keeping it as compatible as possible. Hence also my initial choice (reverted since then) of making universal newlines a compile time option.

Second, and more importantly, universal newlines on output would be a major undertaking. Input code in the Python core uses only fgets() and fread(), and for each of the fgets or fread calls you either have the PyFileObject handy or you can deduce (from code inspection) that the call will always be used on a textfile or always on a binary file. Output code not only uses fwrite() and fputs() but also fprintf() and all its brothers and sisters. Output code occurs literally all over the place (object print methods, for instance). In many of those places all you have is a FILE *. And if the file is open in binary mode (as it needs to be for universal newline input or output) you need to intercept all output (otherwise bare \n characters would appear on Mac or Windows).