I have a question about printing.
When I am printing:
"Work in progress(0%)"
How do I only edit the bold part?
I have a question about printing.
When I am printing:
"Work in progress(0%)"
How do I only edit the bold part?
If printing on the command line you can use:
import time
print "Work in progress( 0%%)", # Python 2 print without newline
for work_done in range(10):
print "\b\b\b\b\b%2d%%)" % work_done, # Backspace then overwrite
time.sleep(1)
This will print your base line and then backspace each time that it is rewritten.
N.B. for python 3 you would need print(whatever, end=None)
Use the .format
:
print "Work in progress({0}%)".format(some_variable_holding_percentage)
percentage = 15
print "Work in progress({:d}%)".format(percentage)
output:
Work in progress(15%)