text: .interactiveshell¶
  Main IPython class.
  7 Classes¶
  - class
  IPython.core.interactiveshell.
  ProvisionalWarning¶
  Bases:
  DeprecationWarning
  Warning class for unstable features
  - class
  IPython.core.interactiveshell.
  SeparateUnicode(default_value=traitlets.Undefined, allow_none=False, read_only=None, help=None, config=None, **kwargs)¶
  Bases:
  traitlets.traitlets.Unicode
  A Unicode subclass to validate separate_in, separate_out, etc.
  This is a Unicode based trait that converts ‘0’->’’ and
  '\\n'->'\n'.
  - class
  IPython.core.interactiveshell.
  ExecutionInfo(raw_cell, store_history, silent, shell_futures)¶
  The arguments used for a call to
  InteractiveShell.run_cell()
  Stores information about what is going to happen.
  - class
  IPython.core.interactiveshell.
  ExecutionResult(info)¶
  The result of a call to
  InteractiveShell.run_cell()
  Stores information about what took place.
  - class
  IPython.core.interactiveshell.
  InteractiveShell(**kwargs)¶
  Bases:
  traitlets.config.configurable.SingletonConfigurable
  An enhanced, interactive shell for Python.
  __init__(ipython_dir=None, profile_dir=None, user_module=None, user_ns=None, custom_exceptions=((),.
  - property.
  check_complete(code: str) → Tuple[str, (str) – When status is ‘incomplete’, this is some whitespace to insert on the next line of the prompt.
  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. [1]: x = ‘hello’
  In [2]: _ip.complete(‘x.l’) Out[2]: (‘x.l’, [‘x.ljust’, ‘x.lower’, ‘x.lstrip’])
  debugger(force=False)¶
  Call the 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.
  debugger_cls¶
  alias of
  IPython.core.debugger.Pdb
  define_macro(name, themacro)¶
  Define a new macro.
  import_all (optional, bool, default: True) – Whether to do
  from numpy import *and
  from pylab import *in addition to module imports.
  welcome_message (deprecated) – This argument is ignored, no welcome message will be displayed..
  - 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.
  raw (bool, optional) – By default, the processed input is used. If this is true, the raw input history is used instead..
  - Parameters
  target (str) – A string specifying code to retrieve. This will be tried respectively as: ranges of input history (see %history for syntax), url, corresponding .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
  get_exception_only(exc_tuple=None)¶
  Return as a string (ending with a newline) the exception that just occurred, without any traceback.
  get_local_scope(stack_depth)¶
  Get local scope at given stack depth.
  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.
  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), programmatically (such as in test suites) or out-of-process (typically over the network by remote frontends).
  init_deprecation_warnings()¶
  register default filter for deprecation warning.
  This will allow deprecation warning of function used interactively to show warning to users, and still hide deprecation warning from libraries import. them..
  - property
  input_splitter¶
  Make this available for backward compatibility (pre-7.0 release) with existing code.
  For example, ipykernel ipykernel currently uses
  shell.input_splitter.check_complete.
  object_inspect_mime(oname, detail_level=0)¶
  Get object info as a mimebundle of formatted representations.
  A mimebundle is a dictionary, keyed by mime-type. It must always have the key
  'text/plain'..
  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
  whomagic..
  - Parameters
  regex (string or compiled pattern, optional) – A regular expression pattern that will be used in searching variable names in the users namespaces.
  - async
  run_ast_nodes(nodelist: List[_ast.AST], cell_name: str, interactivity='last_expr', compiler=<built-in function compile>, result=None)¶
  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).
  ‘all’, ‘last’, ‘last_expr’ , ‘last_expr_or_assign’ 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) ‘last_expr_or_assign’ will run the last expression or the last assignment. Other values for this parameter will raise a ValueError.
  Experimental value: ‘async’ Will try to run top level interactive async/await code in default runner, this will not respect the interactivity setting and will only run the last node if it is an expression.
  compiler (callable) – A function with the same interface as the built-in compile(), to turn the AST nodes into code objects. Default is the built-in compile().
  result (ExecutionResult, optional) – An object to store exceptions that occur during execution.
  - Returns
  True if an exception occurred while running code, False if it finished
  running.
  run_cell(raw_cell, store_history=False, silent=False, shell_futures=True)¶
  Run a complete IPython cell.
  -.
  - Returns
  result
  - Return type
  -
  - async
  run_cell_async(raw_cell: str, store_history=False, silent=False, shell_futures=True, *, transformed_cell: Optional[str] = None, preprocessing_exc_tuple: Optional[traitlets.traitlets.Any] = None) → IPython.core.interactiveshell.ExecutionResult¶
  Run a complete IPython cell asynchronously.
  -.
  transformed_cell (str) – cell that was passed through transformers
  preprocessing_exc_tuple – trace if the transformation failed.
  - Returns
  result (
  ExecutionResult)
  .. versionadded (7.0)
  run_cell_magic(magic_name, line, cell)¶
  Execute the given cell magic.
  - async
  run_code.)
  run_line_magic(magic_name, line, _stack_depth=1)¶
  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.
  _stack_depth (int) – If run_line_magic() is called from magic() then _stack_depth=2. This is added to ensure backward compatibility for use of ‘get_ipython().magic()’
  - async
  runcode.)
  safe_execfile(fname, *where, exit_ignore=False, raise_exceptions=False, shell_futures=False)¶
  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.
  shell_futures (bool (False)) – If True, the code will share future statements with the interactive shell. It will both be affected by previous __future__ imports, and any __future__ imports in the code will affect the shell. If False, __future__ imports are not shared in either direction.
  safe_execfile_ipy(fname, shell_futures=False, raise_exceptions=False)¶
  Like safe_execfile, but for .ipy or .ipynb files with IPython syntax.
  - Parameters
  fname (str) – The name of the file to execute. The filename must have a .ipy or .ipynb extension.
  shell_futures (bool (False)) – If True, the code will share future statements with the interactive shell. It will both be affected by previous __future__ imports, and any __future__ imports in the code will affect the shell. If False, __future__ imports are not shared in either direction.
  raise_exceptions (bool (False)) – If True raise exceptions everywhere. Meant for testing..
  If called with no arguments, it acts as a toggle.
  set_custom_completer(completer, pos=0) → None¶
  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.
  completershould have the following signature:
  def completion(self: Completer, text: string) -> List[str]: raise NotImplementedError
  It will be bound to the current Completer instance and pass some text and return a list with current completions to suggest to the user.
  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) –
  loop (execution) –
  run a very good chance of nasty crashes. This (you) –
  should only be used if you really know what you are doing. (facility) –.
  Example:
  In [1]: _ip.set_next_input("Hello Word") In [2]: Hello Word_ # cursor is here
  should_run_async(raw_cell: str, *, transformed_cell=None, preprocessing_exc_tuple=None) → bool¶
  Return whether a cell should be run asynchronously via a coroutine runner, running_compiled_code=False)¶
  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).
  If the syntax error occurred when running a compiled code (i.e. running_compile_code=True), longer stack trace will be displayed.
  showtraceback(exc_tuple=None, filename=None, tb_offset=None, exception_only=False, running_compiled_code(cmd)¶
  Call the given cmd in a subprocess, piping stdout/err
  system_piped(cmd)¶
  Call the given cmd in a subprocess, piping stdout/err
  system_raw(cmd)¶
  Call the given cmd in a subprocess using os.system on Windows or subprocess.call using the system shell on other platforms.
  transform_ast(node)¶
  Apply the AST transformations from self.ast_transformers
  - Parameters
  node (ast.Node) – The root node to be transformed. Typically called with the ast.Module produced by parsing user input.
  - Returns
  An ast.Node corresponding to the node it was called with. Note that it
  may also modify the passed object, so don’t rely on references to the
  original AST.
  transform_cell(raw_cell)¶
  Transform an input cell before parsing it.
  Static transformations, implemented in IPython.core.inputtransformer2, deal with things like
  %magicand
  !systemcommands. These run on all input. Dynamic transformations, for things like unescaped magics and the exit autocall, depend on the state of the interpreter. These only apply to single line inputs.
  These string-based transformations are followed by AST transformations; see
  transform_ast().
  user_expressions(expressions)¶
  Evaluate a dict of expressions in the user’s namespace..
  3 Functions¶
  IPython.core.interactiveshell.
  removed_co_newlocals(function: function) → function¶
  Return a function that do not create a new local scope.
  Given a function, create a clone of this function where the co_newlocal flag has been removed, making this function code actually run in the sourounding scope.
  We need this in order to run asynchronous code in user level namespace.