-5

I have a question about printing.

When I am printing:

"Work in progress(0%)"

How do I only edit the bold part?

JKC
  • 1
  • 1
  • 3

3 Answers3

2

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)

Hassan Mehmood
  • 1,414
  • 1
  • 14
  • 22
Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
0

Use the .format:

 print "Work in progress({0}%)".format(some_variable_holding_percentage)
Bubble Hacker
  • 6,425
  • 1
  • 17
  • 24
0
percentage = 15
print "Work in progress({:d}%)".format(percentage)

output:

Work in progress(15%)
Yaron
  • 10,166
  • 9
  • 45
  • 65