os.linesep under Windows

andres at corrada.com andres at corrada.com
Tue May 30 16:55:08 EDT 2000


On Tue, May 30, 2000 at 04:24:14PM -0400, Fred L. Drake, Jr. wrote:
> 
> Brandon,
>   This isn't the way to use os.linesep.

Fred,

 This one has bitten me in the past, but on a Mac. Am I correct in saying
that the way sys.write( os.linesep ) works on the Windows platform is:

sys.stodout( '\n' )  is outputted as '\r\n' because Python uses '\n' as the
line separator for all platforms. 

Sort of what Brandon does when he says:

>  So now I have hard-coded my newline because I can't use os.linesep.
> NL = '\012' 

The way I got bit on the Mac platform was by writing:

sys.stdout( '\n' )

and I expected to see a "0A" but saw a "0D", since "OD" is the line
separator on the Mac platform.

> Most of the time you won't
> need os.linesep at all; it's largely defined to be informative for
> those applications that do need it.  For all text-mode files, '\n' is
> converted to the host-specific line separator by the underlying C
> libraries; that's the portable approach and should be used in most
> cases.
> 

Fred, out of curiosity, what applications need to worry about os.linesep
and/or what are those few cases where it should be used directly?

------------------------------------------------------
Andres Corrada-Emmanuel   Email: andres at corrada.com
------------------------------------------------------




More information about the Python-list mailing list