Apr-12-2019, 10:07 AM
(Apr-12-2019, 09:52 AM)perfringo Wrote:(Apr-12-2019, 08:30 AM)microphone_head Wrote: I was toying with the idea of being able to write some chars to the Python shell before deleting it to make a progress bar. Can you give an exampleSomething along those lines (no f-strings, should work right away)??
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)
I like this one. Its more obvious to me what its trying to do but the escape code doesn't work on my machine (Python shell). It just fills up the screen with the different states of the progress bar.
Here's a little of what I get to see:
Output:Activity: [-------------------------] 0.0%
Activity: [-------------------------] 1.0%
Activity: [-------------------------] 2.0%
Activity: [#------------------------] 3.0%
Activity: [#------------------------] 4.0%
Activity: [#------------------------] 5.0%
Activity: [##-----------------------] 6.0%
Activity: [##-----------------------] 7.0%
Activity: [##-----------------------] 8.0%

Now wait a minute


PS. I'd do a screen dump but I've forgotten where this system dumps the file
