### Navigation

- index
- modules |
- next |
- previous |
- IPython v0.10.1 documentation »
- The IPython API »

# OutputTrap

## Module: `OutputTrap`

Inheritance diagram for `IPython.OutputTrap`:

Class to trap stdout and stderr and log them separately.

## Classes

### `OutputTrap`

class `IPython.OutputTrap.``OutputTrap`(name='Generic Output Trap', out_head='Standard Output. ', err_head='Standard Error. ', sum_sep='n', debug=0, trap_out=0, trap_err=0, quiet_out=0, quiet_err=0)

  Class to trap standard output and standard error. They get logged in StringIO objects which are available as <instance>.out and <instance>.err. The class also offers summary methods which format this data a bit.

  A word of caution: because it blocks messages, using this class can make debugging very tricky. If you are having bizarre problems silently, try turning your output traps off for a while. You can call the constructor with the parameter debug=1 for these cases. This turns actual trapping off, but you can keep the rest of your code unchanged (this has already been a life saver).

  Example:

  # config: trapper with a line of dots as log separator (final ‘n’ needed) config = OutputTrap(‘Config’,’Out ‘,’Err ‘,’.’*80+’n’)

  # start trapping output config.trap_all()

  # now all output is logged ... # do stuff...

  # output back to normal: config.release_all()

  # print all that got logged: print config.summary()

  # print individual raw data: print config.out.getvalue() print config.err.getvalue()

  `__init__`()
  `flush`()

    Flush stdout and stderr

  `flush_all`()

    Flush stdout and stderr

  `flush_err`()

    Flush the stdout log. All data held in the log is lost.

  `flush_out`()

    Flush the stdout log. All data held in the log is lost.

  `release`()

    Release both stdout and stderr.

    Cacthes and discards OutputTrapError exceptions raised.

  `release_all`()

    Release both stdout and stderr.

    Cacthes and discards OutputTrapError exceptions raised.

  `release_err`()

    Release stderr.

  `release_out`()

    Release stdout.

  `summary`()

    Return as a string the log from stdout and stderr, prepending a separator to each (defined in __init__ as sum_sep).

  `summary_all`()

    Return as a string the log from stdout and stderr, prepending a separator to each (defined in __init__ as sum_sep).

  `summary_err`()

    Return as a string the log from stderr.

  `summary_out`()

    Return as a string the log from stdout.

  `trap`()

    Trap and log both stdout and stderr.

    Cacthes and discards OutputTrapError exceptions raised.

  `trap_all`()

    Trap and log both stdout and stderr.

    Cacthes and discards OutputTrapError exceptions raised.

  `trap_err`()

    Trap and log stderr.

  `trap_out`()

    Trap and log stdout.

### `OutputTrapError`

class `IPython.OutputTrap.``OutputTrapError`(args=None)

  Bases: `exceptions.Exception`

  Exception for OutputTrap class.

  `__init__`()

### Navigation

- index
- modules |
- next |
- previous |
- IPython v0.10.1 documentation »
- The IPython API »