Module: terminal.interactiveshell — IPython 2.3.1 documentation

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »

# Module: `terminal.interactiveshell`

Subclass of InteractiveShell for terminal based frontends.

## 2 Classes

class `IPython.terminal.interactiveshell.` `TerminalMagics`(shell)

  Bases: `IPython.core.magic.Magics`

  `__init__`(shell)
  `autoindent`(parameter_s='')

    Toggle autoindent on/off (if available).

  `cpaste`(parameter_s='')

    Paste & execute a pre-formatted code block from clipboard.

    You must terminate the block with ‘–’ (two minus-signs) or Ctrl-D alone on the line. You can also provide your own sentinel with ‘%paste -s %%’ (‘%%’ is the new sentinel for this operation).

    The block is dedented prior to execution to enable execution of method definitions. ‘>’ and ‘+’ characters at the beginning of a line are ignored, to allow pasting directly from e-mails, diff files and doctests (the ‘...’ continuation prompt is also stripped). The executed block is also assigned to variable named ‘pasted_block’ for later editing with ‘%edit pasted_block’.

    You can also pass a variable name as an argument, e.g. ‘%cpaste foo’. This assigns the pasted block to variable ‘foo’ as string, without dedenting or executing it (preceding >>> and + is still stripped)

    ‘%cpaste -r’ re-executes the block previously entered by cpaste. ‘%cpaste -q’ suppresses any additional output messages.

    Do not be alarmed by garbled output on Windows (it’s a readline bug). Just press enter and type – (and press enter again) and the block will be what was just pasted.

    IPython statements (magics, shell escapes) are not supported (yet).

    See also

    `paste`
      automatically pull code from clipboard.

    Examples

        In [8]: %cpaste
        Pasting code; enter '--' alone on the line to stop.
        :>>> a = ["world!", "Hello"]
        :>>> print " ".join(sorted(a))
        :--
        Hello world!

  `paste`(parameter_s='')

    Paste & execute a pre-formatted code block from clipboard.

    The text is pulled directly from the clipboard without user intervention and printed back on the screen before execution (unless the -q flag is given to force quiet mode).

    The block is dedented prior to execution to enable execution of method definitions. ‘>’ and ‘+’ characters at the beginning of a line are ignored, to allow pasting directly from e-mails, diff files and doctests (the ‘...’ continuation prompt is also stripped). The executed block is also assigned to variable named ‘pasted_block’ for later editing with ‘%edit pasted_block’.

    You can also pass a variable name as an argument, e.g. ‘%paste foo’. This assigns the pasted block to variable ‘foo’ as string, without executing it (preceding >>> and + is still stripped).

    Options:

    > -r: re-executes the block previously entered by cpaste.

    > -q: quiet mode: do not echo the pasted text back to the terminal.

    IPython statements (magics, shell escapes) are not supported (yet).

    See also

    `cpaste`
      manually paste code into terminal until you mark its end.
  `rerun_pasted`(name='pasted_block')

    Rerun a previously pasted command.

  `store_or_execute`(block, name)

    Execute a block, or store it in a variable, per the user’s request.

class `IPython.terminal.interactiveshell.` `TerminalInteractiveShell`(config=None, ipython_dir=None, profile_dir=None, user_ns=None, user_module=None, custom_exceptions=((), None), usage=None, banner1=None, banner2=None, display_banner=None, **kwargs)

  Bases: `IPython.core.interactiveshell.InteractiveShell`

  `__init__`(config=None, ipython_dir=None, profile_dir=None, user_ns=None, user_module=None, custom_exceptions=((), None), usage=None, banner1=None, banner2=None, display_banner=None, **kwargs)
  `ask_exit`()

    Ask the shell to exit. Can be overiden and used as a callback.

  `edit_syntax_error`()

    The bottom half of the syntax error handler called in the main loop.

    Loop until syntax error is fixed or user cancels.

  static `enable_gui`(gui=None, app=None)

    Switch amongst GUI input hooks by name.

  `exit`()

    Handle interactive exit.

    This method calls the ask_exit callback.

  `interact`(display_banner=None)

    Closely emulate the interactive Python console.

  `mainloop`(display_banner=None)

    Start the mainloop.

    If an optional banner argument is given, it will override the internally created default banner.

  `raw_input`(prompt='')

    Write a prompt and read a line.

    The returned line does not include the trailing newline. When the user enters the EOF key sequence, EOFError is raised.

    Parameters: | prompt : str, optional A string to be printed to prompt the user.

## 2 Functions

`IPython.terminal.interactiveshell.` `get_default_editor`()

`IPython.terminal.interactiveshell.` `get_pasted_lines`(sentinel, l_input=<function input at 0xad4e3fe8c0>, quiet=False)

  Yield pasted lines until the user enters the given sentinel value.

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »