string literals in windows dont show up!

Chris Liechti cliechti at gmx.net
Thu Nov 22 01:44:33 CET 2001


[posted and mailed]

"Chris Fonnesbeck" <fonnesbeck_chris at yahoo.com> wrote in 
news:mailman.1006383692.28423.python-list at python.org:

> I am trying to append literals (i.e. \n, \r) to the end of lines in a
> text output file.  However, when the file is brought up in the windows
> notepad, there is no line feed or carriage return.  Any idea about how
> to make windows recognize these literals.  Works fine in linux (no big
> surprise there!)
> 
> Thanks
> Chris Fonnesbeck
> 

if you use the "b" modes under windows [eg. open(filname,"wb")] the data is 
written as you write it, no conversion (b for binary data). but if you 
specify only "w" (or "r")  cr-lf <-> lf transformation is done. (on 
linux/unix no such conversion is needed as "\n" is the linefeed which is 
the natural line break on these OS)

this should write two lines, on windows with cr-lf line endings
>>> open("test.txt","w").write("line1\nline2\")

does this help? if not, try to post a small python example to illustrate 
your problem.

chris



-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list