cursor positioning

Mage mage at mage.hu
Mon Jul 11 11:06:43 EDT 2005


James Carroll wrote:

>I haven't tried this myself, but I think the secret to displaying a
>continuously updating %done on the command line is to
>    print "file 100, 1% done"
>
>then send exactly 7 backspaces to the terminal, then print 2% done...
>so the backspaces will write over the previous text.
>
>Backspace is a \x08 (ascii character with the value 8.)
>
>It _could_ work...
>
>  
>
I tried but printing backslashes won't work in a loop (i think the
screen was not refreshed correctly). You can use stdout and flush.

Actually I am using this:

    for (s,i) in [(list[i],i) for i in range(len(list))]:
        content = file(s).read()
        sys.stdout.write(chr(8)*35 + str(i + 1) + ' of ' +
str(len(list)) + ' files read')
        sys.stdout.flush()

       Mage




More information about the Python-list mailing list