print, sys.stdout & % complete HELP

bragib at my-deja.com bragib at my-deja.com
Wed May 24 03:38:55 CEST 2000


Hi:

I am trying to print a status message to a terminal window which tells
the user percent complete.

This is the way I went about it in pseudo terms

def percentComplete(lineNo, lines, fileName):
    msg = 'Scanning file %s, %i%s complete.'
    percentComplete = int(round(100*lineNo/lines))
    if divmod(percentComplete, 5)[1]:  # every 5%
        backspace = '\b'*len(oldStatus)
        msg = backspace + msg %(fileName, percentComplete, '%')
        print msg,
        oldStatus = msg

Now I have the problem as follows:
prompt>Scanning file longLongLongName.fil, 100% complete.

Then when I start scanning a file witha shorter name I
get
prompt>Scanning file short.fil, 20% complete. ete.  <--- Oops something
did not get erased.

I have even tried to add spaces to the end of msg such as
msg = backspace + msg % (fileName, percentComplete, '%') + ' '*20

this seems to work if I add a very very large number of white spaces
a hundred or so.  I don't want to do this. I would like to fully
understand what goes on when I issue a print statement and how to work
with this.


Bragi


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list