Show More
@@ -7,6 +7,7 b' Authors' | |||
|
7 | 7 | ------- |
|
8 | 8 | * Robert Kern |
|
9 | 9 | * Fernando Perez |
|
10 | * Thomas Kluyver | |
|
10 | 11 | """ |
|
11 | 12 | |
|
12 | 13 | # Note: though it might be more natural to name this module 'compiler', that |
@@ -2134,9 +2134,9 b' class InteractiveShell(Configurable, Magic):' | |||
|
2134 | 2134 | self.execution_count += 1 |
|
2135 | 2135 | return None |
|
2136 | 2136 | |
|
2137 |
interactivity = |
|
|
2137 | interactivity = 'last' # Last node to be run interactive | |
|
2138 | 2138 | if len(cell.splitlines()) == 1: |
|
2139 |
interactivity = |
|
|
2139 | interactivity = 'all' # Single line; run fully interactive | |
|
2140 | 2140 | |
|
2141 | 2141 | self.run_ast_nodes(code_ast.body, cell_name, interactivity) |
|
2142 | 2142 | |
@@ -2147,7 +2147,7 b' class InteractiveShell(Configurable, Magic):' | |||
|
2147 | 2147 | # Each cell is a *single* input, regardless of how many lines it has |
|
2148 | 2148 | self.execution_count += 1 |
|
2149 | 2149 | |
|
2150 |
def run_ast_nodes(self, nodelist, cell_name, interactivity= |
|
|
2150 | def run_ast_nodes(self, nodelist, cell_name, interactivity='last'): | |
|
2151 | 2151 | """Run a sequence of AST nodes. The execution mode depends on the |
|
2152 | 2152 | interactivity parameter. |
|
2153 | 2153 | |
@@ -2155,20 +2155,25 b' class InteractiveShell(Configurable, Magic):' | |||
|
2155 | 2155 | ---------- |
|
2156 | 2156 | nodelist : list |
|
2157 | 2157 | A sequence of AST nodes to run. |
|
2158 | interactivity : int | |
|
2159 | At 0, all nodes are run in 'exec' mode. At '1', the last node alone | |
|
2160 | is run in interactive mode (so the result of an expression is shown). | |
|
2161 | At 2, all nodes are run in interactive mode. | |
|
2158 | cell_name : str | |
|
2159 | Will be passed to the compiler as the filename of the cell. Typically | |
|
2160 | the value returned by ip.compile.cache(cell). | |
|
2161 | interactivity : str | |
|
2162 | 'all', 'last' or 'none', specifying which nodes should be run | |
|
2163 | interactively (displaying output from expressions). Other values for | |
|
2164 | this parameter will raise a ValueError. | |
|
2162 | 2165 | """ |
|
2163 | 2166 | if not nodelist: |
|
2164 | 2167 | return |
|
2165 | 2168 | |
|
2166 |
if interactivity == |
|
|
2169 | if interactivity == 'none': | |
|
2167 | 2170 | to_run_exec, to_run_interactive = nodelist, [] |
|
2168 |
elif interactivity == |
|
|
2171 | elif interactivity == 'last': | |
|
2169 | 2172 | to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:] |
|
2170 | else: | |
|
2173 | elif interactivity == 'all': | |
|
2171 | 2174 | to_run_exec, to_run_interactive = [], nodelist |
|
2175 | else: | |
|
2176 | raise ValueError("Interactivity was %r" % interactivity) | |
|
2172 | 2177 | |
|
2173 | 2178 | exec_count = self.execution_count |
|
2174 | 2179 | if to_run_exec: |
General Comments 0
You need to be logged in to leave comments.
Login now