Run results
Note It's best to run under the console.
#!/usr/bin/env python#-*-coding:utf-8-*-#@Time: 18-5-21 pm 3:44#@Author: LK#@File: progress bar. PY#@Software: PycharmImportSYSImport TimedefProcess_bar (precent, width=50): Use_num= Int (precent*width) space_num= Int (width-use_num) precent= precent*100#The first one is the same as the last one. trapezoid display, middle two correct, but error in Python2 # #print (' [%s%s]%d%% '% (use_num* ' # ', space_num* ', precent)) #print (' [%s%s]%d%% '% (use_num* ' # ', space_num* ', precent), end= ' \ R ') Print('[%s%s]%d%%'% (use_num*'#', space_num*' ', precent), File=sys.stdout,flush=true, end='\ r') #print (' [%s%s]%d%% '% (use_num* ' # ', space_num* ', precent), file=sys.stdout,flush=true)if __name__=='__main__': forIinchRange (21): Precent= I/20Process_bar (precent) time.sleep (0.2) Print('\ n')
Python Implementation progress bar