A more elegant way to flush print buffer?
Yu Wang
Yu.Wang at synopsys.com
Mon May 26 21:57:25 EDT 2003
Chuck Swiger wrote:
> 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
>
>
Glad to see a differnt implementation of flush()
But....it doesn't work on my Linux /Python2.2.2 environment.
Since I'm not at all familia with curses,I would get more information
from you experts.
errors like this:
File "/usr/local/python/lib/python2.2/curses/wrapper.py", line 44, in
wrapper
res = apply(func, (stdscr,) + rest)
TypeError: 'str' object is not callable
>
--
Love Your Family!
Yu Wang
More information about the Python-list
mailing list