writelines() or write()

John W. Baxter jwbnews at scandaroon.com
Fri Jun 23 18:00:39 EDT 2000


In article <3953C7B9.E32E8599 at seas.upenn.edu>, dwhite2 at seas.upenn.edu 
wrote:

> strings = ['one \r', 'two \r', 'three \r}
> outfile.writelines(strings)
> ---
> outfile looks like this:
> 'three '
> ---
> What I want to have happen of course is:
> 'one '
> 'two '
> 'three '

Use of \n (newline, meaning whatever that is on the machine you're 
working on) rather than \r would be a good first step.  Clearly you 
didn't cut and paste, otherwise the code as shown wouldn't have done 
anything.

The file I get on my BSDi system is (thanks, hexdump)
6e6f 2065 740d 6f77 0d20 6874 6572 2065 000d
just as you directed.

Note that the \r is faithfully reproduced as 0x0d.  With some commands, 
nothing will be seen because the file has no complete lines or because 
the trailing CR wipes out the 'three' (cat on BSDi)...with others, the 
[virtual] Carrier will Return with each \r, and the next line overwrites 
the prior line...that's likely what you're seeing.  And the old less on 
BSDi will show

one ^Mtwo ^Mthree 

(CR is control-M).

  --John

-- 
John W. Baxter   Port Ludlow, WA USA  jwbnews at scandaroon.com



More information about the Python-list mailing list