IPython Documentation

Table Of Contents

Previous topic

core.inputsplitter

Next topic

core.ipapi

This Page

core.interactiveshell

Module: core.interactiveshell

Inheritance diagram for IPython.core.interactiveshell:

Main IPython class.

Classes

Bunch

class IPython.core.interactiveshell.Bunch

InteractiveShell

class IPython.core.interactiveshell.InteractiveShell(config=None, ipython_dir=None, profile_dir=None, user_module=None, user_ns=None, custom_exceptions=((), None))

Bases: IPython.config.configurable.SingletonConfigurable

An enhanced, interactive shell for Python.

__init__(config=None, ipython_dir=None, profile_dir=None, user_module=None, user_ns=None, custom_exceptions=((), None))
alias_manager

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

all_ns_refs

Get a list of references to all the namespace dictionaries in which IPython might store a user-created object.

Note that this does not include the displayhook, which also caches objects from the output.

ask_yes_no(prompt, default=None)
ast_node_interactivity

An enum that whose value must be in a given sequence.

atexit_operations()

This will be executed at the time of exit.

Cleanup operations and saving of persistent data that is done unconditionally by IPython should be performed here.

For things that may depend on startup flags or platform specifics (such as having readline or not), register a separate atexit function in the code that has the appropriate information, rather than trying to clutter

auto_rewrite_input(cmd)

Print to the screen the rewritten form of the user’s command.

This shows visual feedback by rewriting input lines that cause automatic calling to kick in, like:

/f x

into:

------> f(x)

after the user’s input prompt. This helps the user understand that the input line was transformed automatically by IPython.

autocall

An enum that whose value must be in a given sequence.

autoindent

A casting version of the boolean trait.

automagic

A casting version of the boolean trait.

builtin_trap

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

cache_main_mod(ns, fname)

Cache a main module’s namespace.

When scripts are executed via %run, we must keep a reference to the namespace of their __main__ module (a FakeModule instance) around so that Python doesn’t clear it, rendering objects defined therein useless.

This method keeps said reference in a private dict, keyed by the absolute path of the module object (which corresponds to the script path). This way, for multiple executions of the same script we only keep one copy of the namespace (the last one), thus preventing memory leaks from old references while allowing the objects from the last execution to be accessible.

Note: we can not allow the actual FakeModule instances to be deleted, because of how Python tears down modules (it hard-sets all their references to None without regard for reference counts). This method must therefore make a copy of the given namespace, to allow the original module’s __dict__ to be cleared and reused.

Parameters :

ns : a namespace (a dict, typically)

fname : str

Filename associated with the namespace.

Examples

In [10]: import IPython

In [11]: _ip.cache_main_mod(IPython.__dict__,IPython.__file__)

In [12]: IPython.__file__ in _ip._main_ns_cache Out[12]: True

cache_size

An integer trait.

Longs that are unnecessary (<= sys.maxint) are cast to ints.

call_pdb

Control auto-activation of pdb at exceptions

classmethod class_config_section()

Get the config class config section

classmethod class_get_help(inst=None)

Get the help string for this class in ReST format.

If inst is given, it’s current trait values will be used in place of class defaults.

classmethod class_get_trait_help(trait, inst=None)

Get the help string for a single trait.

If inst is given, it’s current trait values will be used in place of the class default.

classmethod class_print_help(inst=None)

Get the help string for a single trait and print it.

classmethod class_trait_names(**metadata)

Get a list of all the names of this classes traits.

This method is just like the trait_names() method, but is unbound.

classmethod class_traits(**metadata)

Get a list of all the traits of this class.

This method is just like the traits() method, but is unbound.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

cleanup()
classmethod clear_instance()

unset _instance for this class and singleton parents.

clear_main_mod_cache()

Clear the cache of main modules.

Mainly for use by utilities like %reset.

Examples

In [15]: import IPython

In [16]: _ip.cache_main_mod(IPython.__dict__,IPython.__file__)

In [17]: len(_ip._main_ns_cache) > 0 Out[17]: True

In [18]: _ip.clear_main_mod_cache()

In [19]: len(_ip._main_ns_cache) == 0 Out[19]: True

color_info

A casting version of the boolean trait.

colors

An enum of strings that are caseless in validate.

colors_force

A casting version of the boolean trait.

complete(text, line=None, cursor_pos=None)

Return the completed text and a list of completions.

Parameters :

text : string

A string of text to be completed on. It can be given as empty and instead a line/position pair are given. In this case, the completer itself will split the line like readline does.

line : string, optional

The complete line that text is part of.

cursor_pos : int, optional

The position of the cursor on the input line.

Returns :

text : string

The actual text that was completed.

matches : list

A sorted list with all possible completions.

The optional arguments allow the completion to take more context into :

account, and are part of the low-level completion API. :

This is a wrapper around the completion mechanism, similar to what :

readline does at the command line when the TAB key is hit. By :

exposing it as a method, it can be used by other non-readline :

environments (such as GUIs) for text completion. :

Simple usage example: :

In [1]: x = ‘hello’ :

In [2]: _ip.complete(‘x.l’) :

Out[2]: (‘x.l’, [‘x.ljust’, ‘x.lower’, ‘x.lstrip’]) :

config

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

created = None
debug

A casting version of the boolean trait.

debugger(force=False)

Call the pydb/pdb debugger.

Keywords:

  • force(False): by default, this routine checks the instance call_pdb

flag and does not actually invoke the debugger if the flag is false. The ‘force’ option forces the debugger to activate even if the flag is false.

deep_reload

A casting version of the boolean trait.

default_user_namespaces = True
define_macro(name, themacro)

Define a new macro

Parameters :

name : str

The name of the macro.

themacro : str or Macro

The action to do upon invoking the macro. If a string, a new Macro object is created by passing the string to it.

del_var(varname, by_name=False)

Delete a variable from the various namespaces, so that, as far as possible, we’re not keeping any hidden references to it.

Parameters :

varname : str

The name of the variable to delete.

by_name : bool

If True, delete variables with the given name in each namespace. If False (default), find the variable in the user namespace, and delete references to it.

disable_failing_post_execute

A casting version of the boolean trait.

display_formatter

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

display_pub_class

A trait whose value must be a subclass of a specified class.

display_trap

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

displayhook_class

A trait whose value must be a subclass of a specified class.

drop_by_id(variables)

Remove a dict of variables from the user namespace, if they are the same as the values in the dictionary.

This is intended for use by extensions: variables that they’ve added can be taken back out if they are unloaded, without removing any that the user has overwritten.

Parameters :

variables : dict

A dictionary mapping object names (as strings) to the objects.

enable_gui(gui=None)
enable_pylab(gui=None, import_all=True)

Activate pylab support at runtime.

This turns on support for matplotlib, preloads into the interactive namespace all of numpy and pylab, and configures IPython to correctly interact with the GUI event loop. The GUI backend to be used can be optionally selected with the optional :param:`gui` argument.

Parameters :

gui : optional, string

If given, dictates the choice of matplotlib GUI backend to use (should be one of IPython’s supported backends, ‘qt’, ‘osx’, ‘tk’, ‘gtk’, ‘wx’ or ‘inline’), otherwise we use the default chosen by matplotlib (as dictated by the matplotlib build-time options plus the user’s matplotlibrc configuration file). Note that not all backends make sense in all contexts, for example a terminal ipython can’t display figures inline.

ev(expr)

Evaluate python expression expr in user namespace.

Returns the result of evaluation

ex(cmd)

Execute a normal python statement in user namespace.

excepthook(etype, value, tb)

One more defense for GUI apps that call sys.excepthook.

GUI frameworks like wxPython trap exceptions and call sys.excepthook themselves. I guess this is a feature that enables them to keep running after exceptions that would otherwise kill their mainloop. This is a bother for IPython which excepts to catch all of the program exceptions with a try: except: statement.

Normally, IPython sets sys.excepthook to a CrashHandler instance, so if any app directly invokes sys.excepthook, it will look to the user like IPython crashed. In order to work around this, we can disable the CrashHandler and replace it with this excepthook instead, which prints a regular traceback using our InteractiveTB. In this fashion, apps which call sys.excepthook will generate a regular-looking exception from IPython, and the CrashHandler will only be triggered by real IPython crashes.

This hook should be used sparingly, only in places which are not likely to be true IPython errors.

execution_count

An integer trait.

Longs that are unnecessary (<= sys.maxint) are cast to ints.

exit_now

A casting version of the boolean trait.

exiter

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

extension_manager

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

extract_input_lines(range_str, raw=False)

Return as a string a set of input history slices.

Parameters :

range_str : string

The set of slices is given as a string, like “~5/6-~4/2 4:8 9”, since this function is for use by magic functions which get their arguments as strings. The number before the / is the session number: ~n goes n back from the current session.

Optional Parameters: :

  • raw(False): by default, the processed input is used. If this is

true, the raw input history is used instead.

Note that slices can be called with two notations: :

N:M -> standard python form, means including items N...(M-1). :

N-M -> include items N..M (closed endpoint). :

filename

A trait for unicode strings.

find_cell_magic(magic_name)

Find and return a cell magic by name.

Returns None if the magic isn’t found.

find_line_magic(magic_name)

Find and return a line magic by name.

Returns None if the magic isn’t found.

find_magic(magic_name, magic_kind='line')

Find and return a magic of the given type by name.

Returns None if the magic isn’t found.

find_user_code(target, raw=True, py_only=False)

Get a code string from history, file, url, or a string or macro.

This is mainly used by magic functions.

Parameters :

target : str

A string specifying code to retrieve. This will be tried respectively as: ranges of input history (see %history for syntax), url, correspnding .py file, filename, or an expression evaluating to a string or Macro in the user namespace.

raw : bool

If true (default), retrieve raw history. Has no effect on the other retrieval mechanisms.

py_only : bool (default False)

Only try to fetch python code, do not try alternative methods to decode file if unicode fails.

Returns :

A string of code. :

ValueError is raised if nothing is found, and TypeError if it evaluates :

to an object of another type. In each case, .args[0] is a printable :

message. :

get_ipython()

Return the currently running IPython instance.

getoutput(cmd, split=True, depth=0)

Get output (possibly including stderr) from a subprocess.

Parameters :

cmd : str

Command to execute (can not end in ‘&’, as background processes are not supported.

split : bool, optional

If True, split the output into an IPython SList. Otherwise, an IPython LSString is returned. These are objects similar to normal lists and strings, with a few convenience attributes for easier manipulation of line-based output. You can use ‘?’ on them for details.

depth : int, optional

How many frames above the caller are the local variables which should be expanded in the command string? The default (0) assumes that the expansion variables are in the stack frame calling this function.

history_length

An integer trait.

Longs that are unnecessary (<= sys.maxint) are cast to ints.

history_manager

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

init_alias()
init_builtins()
init_completer()

Initialize the completion machinery.

This creates completion machinery that can be used by client code, either interactively in-process (typically triggered by the readline library), programatically (such as in test suites) or out-of-prcess (typically over the network by remote frontends).

init_create_namespaces(user_module=None, user_ns=None)
init_display_formatter()
init_display_pub()
init_displayhook()
init_encoding()
init_environment()

Any changes we need to make to the user’s environment.

init_extension_manager()
init_history()

Sets up the command history, and starts regular autosaves.

init_hooks()
init_inspector()
init_instance_attrs()
init_io()
init_ipython_dir(ipython_dir)
init_logger()
init_logstart()

Initialize logging in case it was requested at the command line.

init_magics()
init_payload()
init_pdb()
init_plugin_manager()
init_prefilter()
init_profile_dir(profile_dir)
init_prompts()
init_pushd_popd_magic()
init_readline()

Command history completion/saving/reloading.

init_reload_doctest()
init_syntax_highlighting()
init_sys_modules()
init_traceback_handlers(custom_exceptions)
init_user_ns()

Initialize all user-visible namespaces to their minimum defaults.

Certain history lists are also initialized here, as they effectively act as user namespaces.

Notes

All data structures here are only filled in, they are NOT reset by this method. If they were not empty before, data will simply be added to therm.

init_virtualenv()

Add a virtualenv to sys.path so the user can import modules from it. This isn’t perfect: it doesn’t use the Python interpreter with which the virtualenv was built, and it ignores the –no-site-packages option. A warning will appear suggesting the user installs IPython in the virtualenv, but for many cases, it probably works well enough.

Adapted from code snippets online.

http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv

classmethod initialized()

Has an instance been created?

input_splitter

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

classmethod instance(*args, **kwargs)

Returns a global instance of this class.

This method create a new instance if none have previously been created and returns a previously created instance is one already exists.

The arguments and keyword arguments passed to this method are passed on to the __init__() method of the class upon instantiation.

Examples

Create a singleton class using instance, and retrieve it:

>>> from IPython.config.configurable import SingletonConfigurable
>>> class Foo(SingletonConfigurable): pass
>>> foo = Foo.instance()
>>> foo == Foo.instance()
True

Create a subclass that is retrived using the base class instance:

>>> class Bar(SingletonConfigurable): pass
>>> class Bam(Bar): pass
>>> bam = Bam.instance()
>>> bam == Bar.instance()
True
ipython_dir

A trait for unicode strings.

logappend

A trait for unicode strings.

logfile

A trait for unicode strings.

logstart

A casting version of the boolean trait.

magic(arg_s)

DEPRECATED. Use run_line_magic() instead.

Call a magic function by name.

Input: a string containing the name of the magic function to call and any additional arguments to be passed to the magic.

magic(‘name -opt foo bar’) is equivalent to typing at the ipython prompt:

In[1]: %name -opt foo bar

To call a magic without arguments, simply use magic(‘name’).

This provides a proper Python function to call IPython’s magics in any valid Python code you can type at the interpreter, including loops and compound statements.

magics_manager

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

mktempfile(data=None, prefix='ipython_edit_')

Make a new tempfile and return its filename.

This makes a call to tempfile.mktemp, but it registers the created filename internally so ipython cleans it up at exit time.

Optional inputs:

  • data(None): if data is given, it gets written out to the temp file

immediately, and the file is closed again.

multiline_history

A casting version of the boolean trait.

new_main_mod(ns=None)

Return a new ‘main’ module object for user code execution.

object_info_string_level

An enum that whose value must be in a given sequence.

object_inspect(oname, detail_level=0)
on_trait_change(handler, name=None, remove=False)

Setup a handler to be called when a trait changes.

This is used to setup dynamic notifications of trait changes.

Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).

Parameters :

handler : callable

A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new) or handler(name, old, new).

name : list, str, None

If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.

remove : bool

If False (the default), then install the handler. If True then unintall it.

payload_manager

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

pdb

A casting version of the boolean trait.

plugin_manager

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

pre_readline()

readline hook to be used at the start of each line.

Currently it handles auto-indent only.

prefilter_manager

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

prepare_user_module(user_module=None, user_ns=None)

Prepare the module and namespace in which user code will be run.

When IPython is started normally, both parameters are None: a new module is created automatically, and its __dict__ used as the namespace.

If only user_module is provided, its __dict__ is used as the namespace. If only user_ns is provided, a dummy module is created, and user_ns becomes the global namespace. If both are provided (as they may be when embedding), user_ns is the local namespace, and user_module provides the global namespace.

Parameters :

user_module : module, optional

The current user module in which IPython is being run. If None, a clean module will be created.

user_ns : dict, optional

A namespace in which to run interactive commands.

Returns :

A tuple of user_module and user_ns, each properly initialised. :

profile
profile_dir

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

prompt_in1

A trait for unicode strings.

prompt_in2

A trait for unicode strings.

prompt_out

A trait for unicode strings.

prompts_pad_left

A casting version of the boolean trait.

push(variables, interactive=True)

Inject a group of variables into the IPython user namespace.

Parameters :

variables : dict, str or list/tuple of str

The variables to inject into the user’s namespace. If a dict, a simple update is done. If a str, the string is assumed to have variable names separated by spaces. A list/tuple of str can also be used to give the variable names. If just the variable names are give (list/tuple/str) then the variable values looked up in the callers frame.

interactive : bool

If True (default), the variables will be listed with the who magic.

quiet

A casting version of the boolean trait.

readline_parse_and_bind

An instance of a Python list.

readline_remove_delims

A trait for unicode strings.

readline_use

A casting version of the boolean trait.

refill_readline_hist()
register_post_execute(func)

Register a function for calling after code execution.

reset(new_session=True)

Clear all internal namespaces, and attempt to release references to user objects.

If new_session is True, a new history session will be opened.

reset_selective(regex=None)

Clear selective variables from internal namespaces based on a specified regular expression.

Parameters :

regex : string or compiled pattern, optional

A regular expression pattern that will be used in searching variable names in the users namespaces.

restore_sys_module_state()

Restore the state of the sys module.

run_ast_nodes(nodelist, cell_name, interactivity='last_expr')

Run a sequence of AST nodes. The execution mode depends on the interactivity parameter.

Parameters :

nodelist : list

A sequence of AST nodes to run.

cell_name : str

Will be passed to the compiler as the filename of the cell. Typically the value returned by ip.compile.cache(cell).

interactivity : str

‘all’, ‘last’, ‘last_expr’ or ‘none’, specifying which nodes should be run interactively (displaying output from expressions). ‘last_expr’ will run the last node interactively only if it is an expression (i.e. expressions in loops or other blocks are not displayed. Other values for this parameter will raise a ValueError.

run_cell(raw_cell, store_history=False, silent=False)

Run a complete IPython cell.

Parameters :

raw_cell : str

The code (including IPython code such as %magic functions) to run.

store_history : bool

If True, the raw and translated cell will be stored in IPython’s history. For user code calling back into IPython’s machinery, this should be set to False.

silent : bool

If True, avoid side-effets, such as implicit displayhooks, history, and logging. silent=True forces store_history=False.

run_cell_magic(magic_name, line, cell)

Execute the given cell magic.

Parameters :

magic_name : str

Name of the desired magic function, without ‘%’ prefix.

line : str

The rest of the first input line as a single string.

cell : str

The body of the cell as a (possibly multiline) string.

run_code(code_obj)

Execute a code object.

When an exception occurs, self.showtraceback() is called to display a traceback.

Parameters :

code_obj : code object

A compiled code object, to be executed

Returns :

False : successful execution.

True : an error occurred.

run_line_magic(magic_name, line)

Execute the given line magic.

Parameters :

magic_name : str

Name of the desired magic function, without ‘%’ prefix.

line : str

The rest of the input line as a single string.

runcode(code_obj)

Execute a code object.

When an exception occurs, self.showtraceback() is called to display a traceback.

Parameters :

code_obj : code object

A compiled code object, to be executed

Returns :

False : successful execution.

True : an error occurred.

safe_execfile(fname, *where, **kw)

A safe version of the builtin execfile().

This version will never throw an exception, but instead print helpful error messages to the screen. This only works on pure Python files with the .py extension.

Parameters :

fname : string

The name of the file to be executed.

where : tuple

One or two namespaces, passed to execfile() as (globals,locals). If only one is given, it is passed as both.

exit_ignore : bool (False)

If True, then silence SystemExit for non-zero status (it is always silenced for zero status, as it is so common).

raise_exceptions : bool (False)

If True raise exceptions everywhere. Meant for testing.

safe_execfile_ipy(fname)

Like safe_execfile, but for .ipy files with IPython syntax.

Parameters :

fname : str

The name of the file to execute. The filename must have a .ipy extension.

safe_run_module(mod_name, where)

A safe version of runpy.run_module().

This version will never throw an exception, but instead print helpful error messages to the screen.

Parameters :

mod_name : string

The name of the module to be executed.

where : dict

The globals namespace.

save_sys_module_state()

Save the state of hooks in the sys module.

This has to be called after self.user_module is created.

separate_in

A Unicode subclass to validate separate_in, separate_out, etc.

This is a Unicode based trait that converts ‘0’->’’ and ‘n’->’

‘.

separate_out

A Unicode subclass to validate separate_in, separate_out, etc.

This is a Unicode based trait that converts ‘0’->’’ and ‘n’->’

‘.

separate_out2

A Unicode subclass to validate separate_in, separate_out, etc.

This is a Unicode based trait that converts ‘0’->’’ and ‘n’->’

‘.

set_autoindent(value=None)

Set the autoindent flag, checking for readline support.

If called with no arguments, it acts as a toggle.

set_completer_frame(frame=None)

Set the frame of the completer.

set_custom_completer(completer, pos=0)

Adds a new custom completer function.

The position argument (defaults to 0) is the index in the completers list where you want the completer to be inserted.

set_custom_exc(exc_tuple, handler)

Set a custom exception handler, which will be called if any of the exceptions in exc_tuple occur in the mainloop (specifically, in the run_code() method).

Parameters :

exc_tuple : tuple of exception classes

A tuple of exception classes, for which to call the defined handler. It is very important that you use a tuple, and NOT A LIST here, because of the way Python’s except statement works. If you only want to trap a single exception, use a singleton tuple:

exc_tuple == (MyCustomException,)

handler : callable

handler must have the following signature:

def my_handler(self, etype, value, tb, tb_offset=None):
    ...
    return structured_traceback

Your handler must return a structured traceback (a list of strings), or None.

This will be made into an instance method (via types.MethodType) of IPython itself, and it will be called if any of the exceptions listed in the exc_tuple are caught. If the handler is None, an internal basic one is used, which just prints basic info.

To protect IPython from crashes, if your handler ever raises an exception or returns an invalid result, it will be immediately disabled.

WARNING: by putting in your own exception handler into IPython’s main :

execution loop, you run a very good chance of nasty crashes. This :

facility should only be used if you really know what you are doing. :

set_hook(name, hook) → sets an internal IPython hook.

IPython exposes some of its internal API as user-modifiable hooks. By adding your function to one of these hooks, you can modify IPython’s behavior to call at runtime your own routines.

set_next_input(s)

Sets the ‘default’ input string for the next command line.

Requires readline.

Example:

[D:ipython]|1> _ip.set_next_input(“Hello Word”) [D:ipython]|2> Hello Word_ # cursor is here

set_readline_completer()

Reset readline’s completer to be our own.

show_rewritten_input

A casting version of the boolean trait.

show_usage()

Show a usage message

showindentationerror()

Called by run_cell when there’s an IndentationError in code entered at the prompt.

This is overridden in TerminalInteractiveShell to show a message about the %paste magic.

showsyntaxerror(filename=None)

Display the syntax error that just occurred.

This doesn’t display a stack trace because there isn’t one.

If a filename is given, it is stuffed in the exception instead of what was there before (because Python’s parser always uses “<string>” when reading from a string).

showtraceback(exc_tuple=None, filename=None, tb_offset=None, exception_only=False)

Display the exception that just occurred.

If nothing is known about the exception, this is the method which should be used throughout the code for presenting user tracebacks, rather than directly invoking the InteractiveTB object.

A specific showsyntaxerror() also exists, but this method can take care of calling it if needed, so unless you are explicitly catching a SyntaxError exception, don’t try to analyze the stack manually and simply call this method.

system(cmd)

Call the given cmd in a subprocess, piping stdout/err

Parameters :

cmd : str

Command to execute (can not end in ‘&’, as background processes are not supported. Should not be a command that expects input other than simple text.

system_piped(cmd)

Call the given cmd in a subprocess, piping stdout/err

Parameters :

cmd : str

Command to execute (can not end in ‘&’, as background processes are not supported. Should not be a command that expects input other than simple text.

system_raw(cmd)

Call the given cmd in a subprocess using os.system

Parameters :

cmd : str

Command to execute.

trait_metadata(traitname, key)

Get metadata values for trait by key.

trait_names(**metadata)

Get a list of all the names of this classes traits.

traits(**metadata)

Get a list of all the traits of this class.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

update_config(config)

Fire the traits events when the config is updated.

user_expressions(expressions)

Evaluate a dict of expressions in the user’s namespace.

Parameters :

expressions : dict

A dict with string keys and string values. The expression values should be valid Python expressions, each of which will be evaluated in the user namespace.

Returns :

A dict, keyed like the input expressions dict, with the repr() of each :

value. :

user_global_ns
user_variables(names)

Get a list of variable names from the user’s namespace.

Parameters :

names : list of strings

A list of names of variables to be read from the user namespace.

Returns :

A dict, keyed by the input names and with the repr() of each value. :

var_expand(cmd, depth=0, formatter=<IPython.utils.text.DollarFormatter object at 0x39e1e50>)

Expand python variables in a string.

The depth argument indicates how many frames above the caller should be walked to look for the local namespace where to expand variables.

The global namespace for expansion is always the user’s interactive namespace.

wildcards_case_sensitive

A casting version of the boolean trait.

write(data)

Write a string to the default output

write_err(data)

Write a string to the default error output

xmode

An enum of strings that are caseless in validate.

InteractiveShellABC

class IPython.core.interactiveshell.InteractiveShellABC

Bases: object

An abstract base class for InteractiveShell.

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

NoOpContext

class IPython.core.interactiveshell.NoOpContext

Bases: object

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

ReadlineNoRecord

class IPython.core.interactiveshell.ReadlineNoRecord(shell)

Bases: object

Context manager to execute some code, then reload readline history so that interactive input to the code doesn’t appear when pressing up.

__init__(shell)
current_length()
get_readline_tail(n=10)

Get the last n items in readline history.

RemoteError

class IPython.core.interactiveshell.RemoteError(ename, evalue, traceback, engine_info=None)

Bases: IPython.parallel.error.KernelError

Error raised elsewhere

__init__(ename, evalue, traceback, engine_info=None)
args
ename = None
engine_info = None
evalue = None
message
print_traceback(excid=None)

print my traceback

render_traceback()

render traceback to a list of lines

traceback = None

SeparateUnicode

class IPython.core.interactiveshell.SeparateUnicode(default_value=<IPython.utils.traitlets.NoDefaultSpecified object at 0x3389910>, **metadata)

Bases: IPython.utils.traitlets.Unicode

A Unicode subclass to validate separate_in, separate_out, etc.

This is a Unicode based trait that converts ‘0’->’’ and ‘n’->’

‘.

__init__(default_value=<IPython.utils.traitlets.NoDefaultSpecified object at 0x3389910>, **metadata)

Create a TraitType.

default_value = u''
error(obj, value)
get_default_value()

Create a new instance of the default value.

get_metadata(key)
info()
info_text = 'a unicode string'
init()
instance_init(obj)

This is called by HasTraits.__new__() to finish init’ing.

Some stages of initialization must be delayed until the parent HasTraits instance has been created. This method is called in HasTraits.__new__() after the instance has been created.

This method trigger the creation and validation of default values and also things like the resolution of str given class names in Type and :class`Instance`.

Parameters :

obj : HasTraits instance

The parent HasTraits instance that has just been created.

metadata = {}
set_default_value(obj)

Set the default value on a per instance basis.

This method is called by instance_init() to create and validate the default value. The creation and validation of default values must be delayed until the parent HasTraits class has been instantiated.

set_metadata(key, value)
validate(obj, value)

SpaceInInput

class IPython.core.interactiveshell.SpaceInInput

Bases: exceptions.Exception

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

args
message

Functions

IPython.core.interactiveshell.get_default_colors()
IPython.core.interactiveshell.no_op(*a, **kw)
IPython.core.interactiveshell.softspace(file, newvalue)

Copied from code.py, to remove the dependency