Idiomatic portable way to strip line endings? (fwd)

Peter Ring pri at magnus.dk
Mon Dec 17 03:05:16 EST 2001


Except that files do respect operating system boundaries, the most common
cases being LF-style files appearing in Win32 applications and CR/LF-style
files appearing in *nix applications. In general, it's plain silly to
convert end-of-records just because files are moved around or opened
(through a file system) by a process with another run-time library. Some
operating systems (e.g., VMS) might require a record format conversion for
at least some files, but it's not really the general case.

Kind regards
Peter Ring

"Russ Cox" <rsc at plan9.bell-labs.com> wrote in message
news:mailman.1008535879.30802.python-list at python.org...
> As has already been pointed out, section 7.19.2 of
> the ANSI C99 standard mandates that stdio FILEs
> opened in text mode are sequences of lines, each
> of which is terminated with a newline character.
> I believe this was the case for the C89 standard too.
>
> If you open in binary mode then you have to deal
> with the differing line-ending conventions on
> various systems.  If you open in text mode, you
> should always get a single \n (\012); nothing more,
> nothing less.
>
> Russ
>
>





More information about the Python-list mailing list