Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display lines
#1
Hi,

If my script runs now it shows all the data on screen after the script finishes. Is it possible to show line by line during the execution of the script?

Kind regards,
Patrick
Reply
#2
what are you using as an IDE?
Most have great debuggers that come with the package.
My suggestion would be VSCode, see: VSCode from Start
Reply
#3
That's not what I mean (I think). I want to print line by line when the script runs. So not in debugging mode but during execution of the script!

I mean:
- print loading...
run part of script
- print half way...
run rest of script
- print finsihed...
Reply
#4
The objective is unclear. 'it shows all the data on screen after the script finishes. Is it possible to show line by line during the execution'.

For practical purposes I can't see much value. If script runs in milliseconds (or even second) then printing out during script execution or afterwards can't be distinguished by human eye.

Also - what should be printed out? If code appends items to list then should appended element be printed, whole list printed or something else?

EDIT:

How this is 'printing data' or 'showing line by line'?

Output:
I mean: - print loading... run part of script - print half way... run rest of script - print finsihed...
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#5
I have a script that runs several sql statements to a sql server and the data is analysed and after each run I want to know that it has passed that part of the script. The total time of the script is 25 minutes so if it hangs I would like to know.
Reply
#6
For visualisation one can use status bar.

Implementation depends on code (can you actually measure progress) but generally:

import sys, time

def status(activity, progres, length=25):
    block = int(round(length*progres))
    msg = f'\r{activity}: [{"#"*block}{"-"*(length-block)}] {progres*100:.0f}% {"Ready" if 1 <= progres else ""}'
    sys.stdout.write(msg)
    sys.stdout.flush()

# Usage
lst = []
for i in range(101):
    time.sleep(0.02)
    lst.append(i)
    status('Appending to list', i/100)

print('\r')

pops = len(lst)

while lst:
    time.sleep(0.02)
    lst.pop()
    status('Popping from list', (pops-len(lst)-1)/100)
This will nicely and dynamically show progress and if everything is ok it will finish like this:

Output:
Appending to list: [#########################] 100% Ready Popping from list: [#########################] 100% Ready
time.sleep(0.02) is needed for human eyes only Smile
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#7
Thank you, that is helpfull, I will try to implement it in my code. Have a nice weekend.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,879 May-06-2023, 08:14 AM
Last Post: pramod08728
  Display table field on multiple lines, 'wordwrap' 3python 0 1,763 Aug-06-2021, 08:17 PM
Last Post: 3python
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,212 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,767 Aug-10-2020, 11:01 PM
Last Post: medatib531

Forum Jump:

User Panel Messages

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