python - Print and update a matrix in-place -
i have matrix represented list of lists (but can change representation if help). updating matrix program runs. have matrix displayed on screen in standard way. like
i display update program runs.
for example,
def updatematrix(): #change entries in matrix = [[3,2,3],[1,2,1],[2,8,6]] while(true): updatematrix() display(a) #this ideally change display in place.
what way of doing this? (in fact changing entire columns , rows , want make changed row/column in different color.)
i happy use free libraries might useful.
i'd suggeest using curses library, part of standard python libraries http://docs.python.org/2/library/curses.html
i've included bit of hacked example
import curses import time mywindow = curses.initscr() matrix = [[3,2,3],[1,2,1],[2,8,6]] def updatematrix(m): m[1][1] = m[1][1] * 2 return m def getmarixstring(m): x = '' row in m: x += ' '.join(str(item) item in row) x += "\n" return x z = 10 while z > 1: matrix = updatematrix(matrix) mywindow.addstr(0,0, getmarixstring(matrix)) mywindow.refresh() z -= 1 time.sleep(3) curses.endwin() quit()
Comments
Post a Comment