[SciPy-user] going through a lot of plots
Wed May 13 20:27:21 CDT 2009
>> I find myself in this situation a lot: I'm looking at a sequence of
>> plots, one for each piece of data in a collection. I usually find
>> myself writing a loop with a plot command followed by raw_input()so
>> that I hit enter in the terminal window IPython session to move to
>> next item. I usually make this conditional so that I can process in
>> batch without looking at the plots if I choose.
>> This has the effect of producing a newline in the terminal every time
>> I want to move on to the next plot, which is far from ideal,
>> especially in the situation where I'm not printing anything else in
>> that window.
Old-school alternative is to put the TTY into cbreak (aka "rare" mode,
between "raw" and "cooked"), and capture a single key-hit. (Except
that ^C still breaks, which is handy.) For windows, the C runtime has
a similar getkey function.
Here's windows / posix code for that that I've assembled from various
snippets online; note that the latter uses the well-known decorator
module. I've also included an "iskeydown" function which I find useful
in various situations...
if os.name == 'nt':
c = msvcrt.getch()
if c == '\x00' or c == '\xE0': #functions keys
elif os.name == 'posix':
import tty, sys, select
def _in_cbreak(func, *args, **kws):
fd = sys.stdin.fileno()
old = tty.tcgetattr(fd)
return func(*args, **kws)
tty.tcsetattr(fd, tty.TCSAFLUSH, old)
if select.select([sys.stdin], , , 0) == ([sys.stdin], , ):
More information about the SciPy-user