Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print: Tips and tricks
#11
(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 example Angel ?
Something 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%
Shocked

Now wait a minute Huh . The out I am looking at in my shell window is nothing like whats shown here Cry .

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


Messages In This Thread
print: Tips and tricks - by microphone_head - Apr-11-2019, 09:33 AM
RE: print: Tips and tricks - by perfringo - Apr-11-2019, 11:24 AM
RE: print: Tips and tricks - by Gribouillis - Apr-11-2019, 11:58 AM
RE: print: Tips and tricks - by perfringo - Apr-11-2019, 12:27 PM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 08:30 AM
RE: print: Tips and tricks - by perfringo - Apr-12-2019, 09:35 AM
RE: print: Tips and tricks - by perfringo - Apr-12-2019, 09:52 AM
RE: print: Tips and tricks - by snippsat - Apr-11-2019, 01:15 PM
RE: print: Tips and tricks - by snippsat - Apr-12-2019, 09:34 AM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 09:47 AM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 10:07 AM
RE: print: Tips and tricks - by snippsat - Apr-12-2019, 10:45 AM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 04:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner/Intermediate Tips Ex_database 1 2,062 Sep-27-2019, 04:24 PM
Last Post: Larz60+
  Quick tips and tricks for python juliopa 2 36,389 Jul-03-2019, 09:41 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020