[Pythonmac-SIG] os.linesep?
Joseph J. Strout
joe@strout.net
Tue, 2 Nov 1999 13:38:02 -0800
At 3:08 PM -0500 11/2/99, Andres Corrada wrote:
>Sorry to show my green python coils but I have a couple of more
>questions. Why does Python convert line endings in Windows and Mac?
Because otherwise, you couldn't read or write text files in a
platform-independent way.
>Is this all going back to whether the underlying OS distinguishes between
>text and binary files?
Not whether it distinguishes or not, but rather, what is used to
separate lines. You have to separate lines with something. Mac uses
\r, Unix uses \n, and DOS uses (for some weird reason) \r\n. One's
not better than the other (well, OK, DOS is worse because it uses two
characters), but you have to deal with it.
Python deals with it by defining '\n' as the line separator as far as
Python is concerned, and this is translated transparently to whatever
the underlying OS uses.
>The reason why I want to know is that I'm trying to diagnose my surprise
>at seeing this behavior. Am I being a lazy Unix-style coder, ignorant of
>the wonders of Mac OS or Windows?
Apparently. ;) But consider this: if Python had been written on the
Mac first, then we'd all be using '\r' to separate lines, and the
Unix version would be converting these to '\n' on the fly.
Cheers,
-- Joe
,------------------------------------------------------------------.
| Joseph J. Strout Biocomputing -- The Salk Institute |
| joe@strout.net http://www.strout.net |
`------------------------------------------------------------------'