Permalink
Browse files

Change integer options to string options for interactivity.

  • Loading branch information...
1 parent 4863c51 commit beafaea7dafd48c72a6cc51af79ab039972f7d0b @takluyver committed Apr 7, 2011
Showing with 16 additions and 10 deletions.
  1. +1 −0 IPython/core/compilerop.py
  2. +15 −10 IPython/core/interactiveshell.py
@@ -7,6 +7,7 @@
-------
* Robert Kern
* Fernando Perez
+* Thomas Kluyver
"""
# Note: though it might be more natural to name this module 'compiler', that
@@ -2134,9 +2134,9 @@ def run_cell(self, cell, store_history=True):
self.execution_count += 1
return None
- interactivity = 1 # Last node to be run interactive
+ interactivity = 'last' # Last node to be run interactive
if len(cell.splitlines()) == 1:
- interactivity = 2 # Single line; run fully interactive
+ interactivity = 'all' # Single line; run fully interactive
self.run_ast_nodes(code_ast.body, cell_name, interactivity)
@@ -2147,28 +2147,33 @@ def run_cell(self, cell, store_history=True):
# Each cell is a *single* input, regardless of how many lines it has
self.execution_count += 1
- def run_ast_nodes(self, nodelist, cell_name, interactivity=1):
+ def run_ast_nodes(self, nodelist, cell_name, interactivity='last'):
"""Run a sequence of AST nodes. The execution mode depends on the
interactivity parameter.
Parameters
----------
nodelist : list
A sequence of AST nodes to run.
- interactivity : int
- At 0, all nodes are run in 'exec' mode. At '1', the last node alone
- is run in interactive mode (so the result of an expression is shown).
- At 2, all nodes are run in interactive mode.
+ 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' or 'none', specifying which nodes should be run
+ interactively (displaying output from expressions). Other values for
+ this parameter will raise a ValueError.
"""
if not nodelist:
return
- if interactivity == 0:
+ if interactivity == 'none':
to_run_exec, to_run_interactive = nodelist, []
- elif interactivity == 1:
+ elif interactivity == 'last':
to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
- else:
+ elif interactivity == 'all':
to_run_exec, to_run_interactive = [], nodelist
+ else:
+ raise ValueError("Interactivity was %r" % interactivity)
exec_count = self.execution_count
if to_run_exec:

0 comments on commit beafaea

Please sign in to comment.