Apr-12-2019, 04:03 PM
(Apr-12-2019, 10:45 AM)snippsat Wrote: carriage return\r
and the backspace\b
don't work withinIDLE
(don't use it all) because it uses a text control that doesn't render return/backspace properly. Run it from command line egpython3 pro_bar.py
,or use better REPL like ipython or ptpython. Run it interactive-i
from command should also work as then it will not us IDLE.λ python -i pro_bar.py Activity: [#########################] 100% Ready # Using -i mean that can continue explorer code >>> i 99 >>> status_bar <function status_bar at 0x03410858>Eg with ptpython or ipython i can just copy all code straight into REPL and it work. With IDLE can not copy in code at all,has to use Enter after each line.λ ptpython >>> import sys, time ... ... def status_bar(activity, progres): ... length = 25 ... block = int(round(length*progres)) ... msg = "\r{0}: [{1}] {2}%".format(activity, "#"*block + "-"*(length-block), round(progres*100, 2)) ... if progres >= 1: ... msg += " Ready\r\n" ... sys.stdout.write(msg) ... sys.stdout.flush() ... ... ... ... # usage ... for i in range(100): ... time.sleep(0.1) ... status_bar('Activity', i/100.0) ... status_bar('Activity', 1) Activity: [#########################] 100% Ready
I should have realised that it wouldn't work in the shell when I saw the sys statements, the penny has finally dropped .
I tried it in Geany, and it nearly worked . It keeps everything on one line like expected but it its a all or nothing deal in that instance, because it looks like it waits for all processing to completed before refreshing the output terminal showing the progress bar at 100%. I got the same effect in the Spider editor, and from the command line in a Terminal window.
I think the problem might be because I am not running full blown Linux, because I'm on a RaspberryPi, I don't think everything gets carried across when they compile the apps for my system .
Anyway, thank you all for help , looks like I still got a lot to learn, and maybe a laptop to buy .