IPython Pane Scripting Commands

As described at Recording, Editing, and Writing Macros, macros are Python scripts which automate tasks in Canopy.

Please note that the scripting API in this version of Canopy is likely to change in future releases. We plan for all recorded macros to be supported, but other current scripting commands may be changed.

Here are several commands which you can use to script some common IPython actions.

execute_command(command, hidden=False)

Executes a command at the IPython prompt.

If hidden is True, then the command is executed without displaying any input or output in the IPython interpreter.

If you enter a command at the IPython prompt while you are recording a macro, it will be recorded in the macro script as a call to this method. (At present, this is the only recordable action in the IPython panel.)

code_task = get_active_task()
python_pane = code_task.python_pane
python_pane.execute_command(u'print "hello world"\n')
execute_file(path, hidden=False)

Executes a file at the IPython prompt.

If hidden is True, then the file is executed without displaying any input or output in the IPython interpreter.

code_task = get_active_task()
python_pane = code_task.python_pane
python_pane.execute_file('/tmp/script.py')
history_tail(count)

Returns a list of the final count entries from the end of the local IPython history list.

# Repeat the next-to-last command at the IPython prompt.
# (Invoke this repeatedly to alternate between two commands):
code_task = get_active_task()
python_pane = code_task.python_pane
python_pane.execute_command(python_pane.history_tail(2)[0])