os.linesep under Windows
Brandon Irons
brandonirons at topmail.de
Tue May 30 15:41:46 EDT 2000
import os
import sys
sys.stdout.write( os.linesep )
Under Windows, run this program with:
python test.py > huh.txt
The result is a file size of 3 (not 2) for huh.txt. This is because
sys.stdout.write( os.linesep ) is equivalent to:
sys.stdout.write( os.linesep[0] ) # aka '\015'
sys.stdout.write( os.linesep[1] ) # aka '\012'
and, apparently, when writing a '\012' to stdout, this is expanded
to:
0D 0A
When writing os.linesep, I expect to get: 0D 0A in the output (under
Windows.) Instead I get: 0D 0D 0A.
So now I have hard-coded my newline because I can't use os.linesep.
NL = '\012'
sys.stdout.write( NL ) # yields the expected 0D 0A
So what use is os.linesep if it works in a useless manner under
Windows?
oBrando
More information about the Python-list
mailing list