Apr-12-2019, 10:45 AM
carriage return
Run it from command line eg
Run it interactive
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.
\r
and the backspace \b
don't work within IDLE
(don't use it all) because it uses a text control that doesn't render return/backspace properly.Run it from command line eg
python3 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