The example code of Python dynamic text progress bar

Time:2020-3-18

How to realize dynamic single row refresh? The answer is: overwrite

But how to achieve coverage

The key is not to wrap the line and can back to the start position

Then we need to use the

This thing is to let the cursor back to the initial position of the current line

Remember not to break the line

Upper code

#Text progress bar.py
import time
scale = 50
Print (". Center (scale," - ") // Center
Start = time. Perf_counter() // get start time
for i in range(scale+1):
  a = i*'*'
  b = (scale-i)*'.'
  c = (i/scale)*100
  Dur = time. Perf_counter() // get the current time each time
  Print ("\ R {: ^ 3.0f}% [{} - > {}] {:. 2F} s". Format (C, a, B, DUR), end = ') // output percentage, graph progress and current time used, control end is empty so that line wrapping is not needed
  time.sleep(0.1)
Print ('\ n' + "end execution". Center (scale, '-'))

Operation effect:

summary

The above is an example code of Python dynamic text progress bar introduced by Xiaobian. I hope it can help you!