[IPython-dev] check for "q" or abort in a custom magic-function

Thomas Kluyver takowl@gmail....
Wed Jun 20 10:00:53 CDT 2012


On 20 June 2012 15:44, Alexander Krause <admin@erazor-zone.de> wrote:
> Is there a way to actually call self.ev? I suppose I've to flush some
> stdout buffers to get the output?

Note that it should be self.shell.ev (and likewise for ex()) - this
will become important soon, when we release 0.13.

I'm not quite sure what you mean about stdout buffers, but I think you
want something like this:

# e.g. cmd = "AC.OnOff"
prev_value = self.shell.ev(cmd)
while True:
    time.sleep(sleep_time)
    new_value = self.shell.ev(cmd)
    if new_value != prev_value:
        print("%s changed from %r to %r" % (cmd, prev_value, new_value))
    prev_value = new_value

Checking for a key is trickier, especially across different platforms.
The simplest way is just to use Ctrl+C to interrupt the code.

Best wishes,
Thomas


More information about the IPython-dev mailing list