A more elegant way to flush print buffer?
Chuck Swiger
cswiger at mac.com
Mon May 26 15:08:41 EDT 2003
Teemu Luojola wrote:
> Is there any other way to flush the print buffer than to call
> sys.stdout.flush()?
"print buffer"...? There's no other way to flush stdout than doing the
call, but there are better ways to draw an animated windmill character
than writing backspaces and flushing.
> Take as an example a simple "windmill" practice,
> like the following:
A long time ago, someone clever decided to figure out how to draw
characters and move around the screen quickly in a platform-independant
fashion: this is how termcap and curses came about. Using the following
semantics works much better, or at least the C version does:
--
import curses
from curses import wrapper
def mvaddch(x,y,char): curses.wrapper('mvaddch',y,x,char)
def wrefresh(): curses.wrapper('wrefresh',0)
def FIXCURSOR(): """NA: was used to move the cursor back to another
panel (for user input) to avoid flicker"""
def EDELAY(): """NA: was used to delay for 50 milliseconds via usleep()"""
def explode(x,y):
"""Draw an ASCII explosion at position x,y"""
for index in range(7):
mvaddch(x,y,'-')
wrefresh()
FIXCURSOR()
EDELAY()
mvaddch(x,y,'\\')
wrefresh()
FIXCURSOR()
EDELAY()
mvaddch(x,y,'|')
wrefresh()
FIXCURSOR()
EDELAY()
mvaddch(x,y,'/')
wrefresh()
FIXCURSOR()
EDELAY()
mvaddch(x,y,'*')
wrefresh()
EDELAY()
mvaddch(x,y,'x')
wrefresh()
EDELAY()
EDELAY()
mvaddch(x,y,'.')
wrefresh()
EDELAY()
FIXCURSOR()
if __name__ == "__main__":
explode(10,20)
...only, how does one invoke the underlying curses implementation of
mvaddch and such from Python? Calling curses.wrapper didn't do what I
expected, clearly enough.
-Chuck
More information about the Python-list
mailing list