Interpreter fussy about line endings?

Tim Peters tim_one at email.msn.com
Tue May 4 23:42:27 EDT 1999


[Greg Ewing <greg.ewing at compaq.com>]
> Python 1.5.1 on my Mac refuses to run code written using PythonWin's
> built-in editor, apparently because of different CR/LF conventions. I
> have to load it into Alpha and save it in Mac format before it will
> work!

Facing a related mystery reported by people who downloaded doctest.py using
Netscape and then tried to use it under JPython (yes, both NS and JPython
are implicated in this <wink>), I uploaded the utility linefix.py to the
Python ftp contrib site's System area.  This converts text files among
Windows, Unix and Mac line-end conventions (plus any other conceivable
combination of \r and \n silliness).  If you can run Python, you can use
that.

> Is it meant to be like this?

Too deep for me.

> Why should it care?

Python chews on whatever the platform libc delivers for files opened in text
mode; apparently your platform's libc doesn't convert CR LF to LF (the
Windows version of libc does).

> How is one supposed to write cross-platform Python code if it does
> things like this?

Text files aren't portable in or out of the Python world.  Compiled Python
files (.pyc and .pyo) *are* portable, since they use a platform-independent
binary format.

that's-what-the-world-gets-for-not-letting-guido-define-all-file-
    formats-ly y'rs  - tim






More information about the Python-list mailing list