Carriage Return Problem with Python on Windows
lbates at swamisoft.com
Fri Sep 3 16:20:54 CEST 2004
Here is a sample progress indicator class that should
(I think) answer your questions:
def __init__(self, finalcount, progresschar=None):
# See if caller passed me a character to use on the
# progress bar (like "*"). If not use the block
# character that makes it look like a real progress
if not progresschar: self.block=chr(178)
# Get pointer to sys.stdout so I can use the write/flush
# methods to display the progress bar.
# If the final count is zero, don't start the progress gauge
if not self.finalcount : return
self.f.write(' 1 2 3 4 5 6 7 8 9 0\n')
def progress(self, count):
# Make sure I don't try to go off the end (e.g. >100%)
# If finalcount is zero, I'm done
if percentcomplete < 1: percentcomplete=1
if blockcount > self.blockcount:
for i in range(self.blockcount,blockcount):
if percentcomplete == 100: self.f.write("\n")
if __name__ == "__main__":
from time import sleep
print "testing 1:"
"Canes_Rock" <hinnc at yahoo.com> wrote in message
news:48593215.0409021155.69139a18 at posting.google.com...
> The information posted at:
> 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?).
> I also tried a variation using sys.stdout.write and sys.stdout.flush
> but the root cause is the issue with the carriage return.
> Am I screwed or is there a way around this? I am running Windows XP
> Home Edition using Python version 2.3.3 and IDLE version 1.0.2
> Any help would be appreciated!
More information about the Python-list