The example code of Python dynamic text progress bar


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
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
Print ('\ n' + "end execution". Center (scale, '-'))

Operation effect:


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