I want to run a script, which basicly shows things like:
Installing XXX... [DONE]
Now, at the moment, I use print to print the whole line AFTER the function has succeeded. However, I now want it to print "Installing xxx..." first, and AFTER the function has run, to add the "DONE" tag; but on the same line.
Any ideas?
You can use the
print
statement to do this without importingsys
.The comma on the end of the
print
line preventsprint
from issuing a new line (you should note that there will be an extra space at the end of the output).The Python 3 Solution
Since the above does not work in Python 3, you can do this instead (again, without importing
sys
):The print function accepts an
end
parameter which defaults to"\n"
. Setting it to an empty string prevents it from issuing a new line at the end of the line.If you want to overwrite the previous line (rather than continually adding to it), you can combine
\r
withprint(),
at the end of the print statement. For example,will count 0 to 9, replacing the old number in the console. The
"...DONE!"
will print on the same line as the last counter, 9.In your case for the OP, this would allow the console to display percent complete of the install as a "progress bar", where you can define a begin and end character position, and update the markers in between.