Progress Bar in Python Console on Windows -
i have gone through below 2 links in addition others , have tried examples , suggestions provided, in output progress bar not getting updated, rather new 1 shows, either end of same line or alternately on new line. missing here, can please guide me.
for ease, reproducing of codes (from examples of above threads) have tried , outputs. did understand incorrect update same line or missing. appreciate help. using python 3.4 on windows 7 , getting output on console (no gui).
example 1:
import progressbar import time, sys progress = progressbar.progressbar() in progress(range(80)): time.sleep(0.01)
output 1:
>>> 0% | | 1% | | 2% |# | 3% |## | 5% |### | 6% |#### | 7% |##### | 8% |###### | 10% |####### | 11% |######## | 12% |######### | 13% |######### | 15% |########## | 16% |########### | 17% |############ | 18% |############# | 20% |############## | 21% |############### | 22% |################ | 23% |################# | 25% |################## | 26% |################## | 27% |################### | 28% |#################### | 30% |##################### | 31% |###################### | 32% |####################### | 33% |######################## | 35% |######################### | 36% |########################## | 37% |########################### | 38% |########################### | 40% |############################ | 41% |############################# | 42% |############################## | 43% |############################### | 45% |################################ | 46% |################################# | 47% |################################## | 48% |################################### | 50% |#################################### | 51% |#################################### | 52% |##################################### | 53% |###################################### | 55% |####################################### | 56% |######################################## | 57% |######################################### | 58% |########################################## | 60% |########################################### | 61% |############################################ | 62% |############################################# | 63% |############################################# | 65% |############################################## | 66% |############################################### | 67% |################################################ | 68% |################################################# | 70% |################################################## | 71% |################################################### | 72% |#################################################### | 73% |##################################################### | 75% |###################################################### | 76% |###################################################### | 77% |####################################################### | 78% |######################################################## | 80% |######################################################### | 81% |########################################################## | 82% |########################################################### | 83% |############################################################ | 85% |############################################################# | 86% |############################################################## | 87% |############################################################### | 88% |############################################################### | 90% |################################################################ | 91% |################################################################# | 92% |################################################################## | 93% |################################################################### | 95% |#################################################################### | 96% |##################################################################### | 97% |###################################################################### | 98% |####################################################################### | 100% |########################################################################|
example 2:
for in range(0, 101, 10): sys.stdout.write('\r>> have finished %3d%%\r' % i) sys.stdout.flush() sys.stdout.flush() time.sleep(1) print
output 2:
you have finished 0% >> have finished 10% >> have finished 20% >> have finished 30% >> have finished 40% >> have finished 50% >> have finished 60% >> have finished 70% >> have finished 80% >> have finished 90% >> have finished 100%
example 3:
def update_progress(progress): barlength = 20 # modify change length of progress bar status = "" if isinstance(progress, int): progress = float(progress) if not isinstance(progress, float): progress = 0 status = "error: progress var must float\r\n" if progress < 0: progress = 0 status = "halt...\r\n" if progress >= 1: progress = 1 status = "done...\r\n" block = int(round(barlength*progress)) text = "\rpercent: [{0}] {1}% {2}".format( "="*block + " "*(barlength-block), progress*100, status) sys.stdout.write(text) sys.stdout.flush() print("") print("progress : 0->1") in range(101): time.sleep(0.1) update_progress(i/100.0) print("") print("test completed") time.sleep(1)
output 3:
>>> progress : 0->1 percent: [ ] 0.0% percent: [ ] 1.0% percent: [ ] 2.0% percent: [= ] 3.0% percent: [= ] 4.0% percent: [= ] 5.0% percent: [= ] 6.0% percent: [= ] 7.000000000000001% percent: [== ] 8.0% percent: [== ] 9.0% percent: [== ] 10.0% percent: [== ] 11.0% percent: [== ] 12.0% percent: [=== ] 13.0% percent: [=== ] 14.000000000000002% percent: [=== ] 15.0% percent: [=== ] 16.0% percent: [=== ] 17.0% percent: [==== ] 18.0% percent: [==== ] 19.0% percent: [==== ] 20.0% percent: [==== ] 21.0% percent: [==== ] 22.0% percent: [===== ] 23.0% percent: [===== ] 24.0% percent: [===== ] 25.0% percent: [===== ] 26.0% percent: [===== ] 27.0% percent: [====== ] 28.000000000000004% percent: [====== ] 28.999999999999996% percent: [====== ] 30.0% percent: [====== ] 31.0% percent: [====== ] 32.0% percent: [======= ] 33.0% percent: [======= ] 34.0% percent: [======= ] 35.0% percent: [======= ] 36.0% percent: [======= ] 37.0% percent: [======== ] 38.0% percent: [======== ] 39.0% percent: [======== ] 40.0% percent: [======== ] 41.0% percent: [======== ] 42.0% percent: [========= ] 43.0% percent: [========= ] 44.0% percent: [========= ] 45.0% percent: [========= ] 46.0% percent: [========= ] 47.0% percent: [========== ] 48.0% percent: [========== ] 49.0% percent: [========== ] 50.0% percent: [========== ] 51.0% percent: [========== ] 52.0% percent: [=========== ] 53.0% percent: [=========== ] 54.0% percent: [=========== ] 55.00000000000001% percent: [=========== ] 56.00000000000001% percent: [=========== ] 56.99999999999999% percent: [============ ] 57.99999999999999% percent: [============ ] 59.0% percent: [============ ] 60.0% percent: [============ ] 61.0% percent: [============ ] 62.0% percent: [============= ] 63.0% percent: [============= ] 64.0% percent: [============= ] 65.0% percent: [============= ] 66.0% percent: [============= ] 67.0% percent: [============== ] 68.0% percent: [============== ] 69.0% percent: [============== ] 70.0% percent: [============== ] 71.0% percent: [============== ] 72.0% percent: [=============== ] 73.0% percent: [=============== ] 74.0% percent: [=============== ] 75.0% percent: [=============== ] 76.0% percent: [=============== ] 77.0% percent: [================ ] 78.0% percent: [================ ] 79.0% percent: [================ ] 80.0% percent: [================ ] 81.0% percent: [================ ] 82.0% percent: [================= ] 83.0% percent: [================= ] 84.0% percent: [================= ] 85.0% percent: [================= ] 86.0% percent: [================= ] 87.0% percent: [================== ] 88.0% percent: [================== ] 89.0% percent: [================== ] 90.0% percent: [================== ] 91.0% percent: [================== ] 92.0% percent: [=================== ] 93.0% percent: [=================== ] 94.0% percent: [=================== ] 95.0% percent: [=================== ] 96.0% percent: [=================== ] 97.0% percent: [====================] 98.0% percent: [====================] 99.0% percent: [====================] 100% done... test completed >>>
edit: can see printing on same line happening, appending @ end of last print rather overwriting desired effect. thanks!
>>> import time >>> in range(0, 101, 10): ... print('\ryou have finished %3d%%' % i, end='', flush=true) ... time.sleep(1) ... else: ... print() ... have finished 100% >>>
works me python 3.4.3 on win32...
idle doesn't render carriage returns properly.
look python print 1 line same space. "done, mistake using idle" or implementing backspace in python 3.3.2 shell using idle.
idle more python text editor , no real console... therefore cannot interpret control symbol , print @ same time...
>>> print("asd\rfgh") asdfgh
Comments
Post a Comment