Carriage Return Problem with Python on Windows

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Fri Sep 3 04:33:03 EDT 2004


Canes_Rock wrote:
> The information posted at:
> 
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=slrnarv28n.e4j.TuxTrax%40fortress.tuxnet&rnum=1&prev=/groups%3Fq%3Dsuppress%2Bcarriage%2Breturn%2Bgroup:comp.lang.python.*%26hl%3Den%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.python.*%26selm%3Dslrnarv28n.e4j.TuxTrax%2540fortress.tuxnet%26rnum%3D1
> 
> seemed to provide a solution to eliminating the line feed and causing
> a carriage return for the text displayed in the IDLE window, (I want
> to be able to overwrite displayed text - that is, eliminating the line
> feed from occuring and causing a carriage return).
> 
> The comma at the end of the print command appeared to have eliminated
> the line feed, (\n), but the carriage return, (\r) does not work.  For
> example, (logic borrowed from previously referenced thread):
> 
> for i in range(10) : print '\r' + `i`,
> 
> This produces a small square box before each number, (sorry - can't
> duplicate the small square box here in this posting but if you were to
> substitute X for box the output would look like this):
> 
> X1 X2 X3 X4 X5 X6 X7 X8 X9
> 
> as you can see the line feed has been eliminated but the carriage
> return is not functioning as I would expect, (yes - its always about
> me isn't it?).

With IDLE, I just see 1 2 3 etc. all on one line, i.e. the same as you 
do but without the boxes. PythonWin shows each number on its own line. 
Python at the command prompt works correctly: only 9 is whown in the 
end, since all the other numbers are overwritten. All that on Windows XP 
Professional with Python 2.3.3.

It seems the behavior of '\r' is dependent on the terminal.

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Python-list mailing list