Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print: Tips and tricks
#13
(Apr-12-2019, 10:45 AM)snippsat Wrote: carriage return \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

I should have realised that it wouldn't work in the shell when I saw the sys statements, the penny has finally dropped Blush.

I tried it in Geany, and it nearly worked Dance . 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 Think .

Anyway, thank you all for help Smile, looks like I still got a lot to learn, and maybe a laptop to buy Rolleyes.
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,112 Sep-27-2019, 04:24 PM
Last Post: Larz60+
  Quick tips and tricks for python juliopa 2 42,806 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