Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optimised Display
#1
I a newbie seeking help on control of the displayed print screen.
I have a small array (4,20) which updates very fast and the printed array appendes to the bottom of the previous printout.

I would like to watch the printout to see updates as they occur in each cell.

So I am looking for python/numpy code for screen overwrite (I have tried os.clr without success)

Ideas appreciated!
Reply
#2
for terminal like screens, see: https://docs.python.org/3/howto/curses.html
Reply
#3
Thanks Larz60+ but that's very opaque for a newbie!

I guess I am really asking how to clear (or overwrite or retrace) the shell window.

My searches have not provided anything useful so far.

Maybe it can't be done?

Now there's a challenge !!
Reply
#4
As no-one has yet come up with a simple suggestion, I have resolved the issue by saving the array to a CSV file in Dropbox which I can visit to view the array to check on performance. The downside of this solution is that the array is temporarily unavailable for updating in the program until I close the CSV file.

However, it is a (marginally) acceptable solution.

Incidentally, I also tried a Tkinter window solution, which gave a good display of the array, but stopped the loop running.

Thanks Guys for following this thread.

Astrikor
Reply
#5
Trying to solve a problem without seeing the code is kind of like performing brain surgery in the dark. It's
next to impossible.
If you post code (which ever version you like best), I'm sure you will get some (at least possible) solutions.
Reply
#6
Ok, this trivial code will illustrate the point - you cant watch the changes to the array unless it shows a stable print on the screen, and even if you adjust the window height manually to show just 4 lines, ultimately the loop crashes (exceeds max shell limit ?). Consequently I was looking for some code to either clear the shell display or alternatively to overwrite the previous loop cycle.
import numpy as np
myarray = np.zeros([4,10])
print(myarray)
while True:
    for i in range(4):
        myarray[i,0] = 1 + myarray[i,0]
    print(myarray)
Reply
#7
Hello maybe you could use this:

import os

def clearscr():
    os.system('cls' if os.name=='nt' else 'clear')

# in your code to clear the screen call this function
clearscr()
Reply
#8
Thanks dageci
You mean like this ?
import numpy as np
import os
 
def clearscr():
    os.system('cls' if os.name=='nt' else 'clear')
 
# in your code to clear the screen call this function
clearscr()
myarray = np.zeros([4,10])
print(myarray)
while True:
    for i in range(4):
        myarray[i,0] = 1 + myarray[i,0]
    print(myarray)
    clearscr()
Try it - it doesn't work!

Any other suggestions please?
Astrikor
Reply
#9
Maybe this link can help.
https://teamtreehouse.com/community/clea...ole-or-cmd

They are talking that the only solution could be to assign a shortcut key to Clear all button and then emulating Key presses for that shortcut keys.
Reply


Forum Jump:

User Panel Messages

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