Important
This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.
If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).
Module: core.magics.script
¶
Magic functions for running cells in various scripts.
1 Class¶
- class IPython.core.magics.script.ScriptMagics(**kwargs: Any)¶
Bases:
Magics
Magics for talking to scripts
This defines a base
%%script
cell magic for running a cell with a program in a subprocess, and registers a few top-level magics that call %%script with common interpreters.- __init__(shell=None)¶
Create a configurable given a config config.
- Parameters:
config (Config) – If this is empty, default values are used. If config is a
Config
instance, it will be used to configure the instance.parent (Configurable instance, optional) – The parent Configurable instance of this object.
Notes
Subclasses of Configurable must call the
__init__()
method ofConfigurable
before doing anything else and usingsuper()
:class MyConfigurable(Configurable): def __init__(self, config=None): super(MyConfigurable, self).__init__(config=config) # Then any other code you need to finish initialization.
This ensures that instances will be configured properly.
- event_loop¶
The event loop on which to run subprocesses
Not the main event loop, because we want to be able to make blocking calls and have certain requirements we don’t want to impose on the main loop.
- kill_bg_processes()¶
Kill all BG processes which are still running.
- killbgscripts(_nouse_='')¶
Kill all BG processes started by %%script and its family.
- script_magics: List¶
Extra script cell magics to define
This generates simple wrappers of
%%script foo
as%%foo
.If you want to add script magics that aren’t on your path, specify them in script_paths
- script_paths¶
Dict mapping short ‘ruby’ names to full paths, such as ‘/opt/secret/bin/ruby’
Only necessary for items in script_magics where the default path will not find the right interpreter.
- shebang(line, cell)¶
%shebang [--no-raise-error] [--proc PROC] [--bg] [--err ERR] [--out OUT]
Run a cell via a shell command
The
%%script
line is like the #! line of script, specifying a program (bash, perl, ruby, etc.) with which to run.The rest of the cell is run by that program.
Examples
In [1]: %%script bash ...: for i in 1 2 3; do ...: echo $i ...: done 1 2 3
- options:
- --no-raise-error
Whether you should raise an error message in addition to a stream on stderr if you get a nonzero exit code.
- --proc PROC
The variable in which to store Popen instance. This is used only when –bg option is given.
- --bg
Whether to run the script in the background. If given, the only way to see the output of the command is with –out/err.
- --err ERR
The variable in which to store stderr from the script. If the script is backgrounded, this will be the stderr pipe, instead of the stderr text itself and will not be autoclosed.
- --out OUT
The variable in which to store stdout from the script. If the script is backgrounded, this will be the stdout pipe, instead of the stderr text itself and will not be auto closed.
1 Function¶
- IPython.core.magics.script.script_args(f)¶
single decorator for adding script args