environment/lib/python2.7/site-packages/IPython/core/interactiveshell.py
def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr'):
        """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).
        interactivity : str
          'all', 'last', 'last_expr' 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. Other values
          for this parameter will raise a ValueError.
        """
        if not nodelist:
            return

        if interactivity == 'last_expr':
            if isinstance(nodelist[-1], ast.Expr):
                interactivity = "last"
            else:
                interactivity = "none"

        if interactivity == 'none':
            to_run_exec, to_run_interactive = nodelist, []
        elif interactivity == 'last':
            to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
        elif interactivity == 'all':
            to_run_exec, to_run_interactive = [], nodelist
        else:
            raise ValueError("Interactivity was %r" % interactivity)

        exec_count = self.execution_count

        try:
            for i, node in enumerate(to_run_exec):
                mod = ast.Module([node])
                code = self.compile(mod, cell_name, "exec")
                if self.run_code(code):
                    return True

            for i, node in enumerate(to_run_interactive):
                mod = ast.Interactive([node])
                code = self.compile(mod, cell_name, "single")
                if self.run_code(code):
                    return True

            # Flush softspace
            if softspace(sys.stdout, 0):
                print

        except:
            # It's possible to have exceptions raised here, typically by
            # compilation of odd code (such as a naked 'return' outside a
            # function) that did parse but isn't valid. Typically the exception
            # is a SyntaxError, but it's safest just to catch anything and show
            # the user a traceback.

            # We do only one try/except outside the loop to minimize the impact
            # on runtime, and also because if any node in the node list is
            # broken, we should stop execution completely.
            self.showtraceback()

        return False
def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr'):
        if not nodelist:
            return

        if interactivity == 'last_expr':
            if isinstance(nodelist[-1], ast.Expr):
                interactivity = "last"
            else:
                interactivity = "none"

        if interactivity == 'none':
            to_run_exec, to_run_interactive = nodelist, []
        elif interactivity == 'last':
            to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
        elif interactivity == 'all':
            to_run_exec, to_run_interactive = [], nodelist
        else:
            raise ValueError("Interactivity was %r" % interactivity)

        exec_count = self.execution_count

        try:
            for i, node in enumerate(to_run_exec):
                mod = ast.Module([node])
                code = self.compile(mod, cell_name, "exec")
                if self.run_code(code):
                    return True

            for i, node in enumerate(to_run_interactive):
                mod = ast.Interactive([node])
                code = self.compile(mod, cell_name, "single")
                if self.run_code(code):
                    return True

            # Flush softspace
            if softspace(sys.stdout, 0):
                print

        except:
            # It's possible to have exceptions raised here, typically by
            # compilation of odd code (such as a naked 'return' outside a
            # function) that did parse but isn't valid. Typically the exception
            # is a SyntaxError, but it's safest just to catch anything and show
            # the user a traceback.

            # We do only one try/except outside the loop to minimize the impact
            # on runtime, and also because if any node in the node list is
            # broken, we should stop execution completely.
            self.showtraceback()

        return False
def run_ast_nodes ( self , nodelist , cell_name , interactivity = 'last_expr' ) : if not nodelist : return if interactivity == 'last_expr' : if isinstance ( nodelist [ - 1 ] , ast . Expr ) : interactivity = "last" else : interactivity = "none" if interactivity == 'none' : to_run_exec , to_run_interactive = nodelist , [ ] elif interactivity == 'last' : to_run_exec , to_run_interactive = nodelist [ : - 1 ] , nodelist [ - 1 : ] elif interactivity == 'all' : to_run_exec , to_run_interactive = [ ] , nodelist else : raise ValueError ( "Interactivity was %r" % interactivity ) exec_count = self . execution_count try : for i , node in enumerate ( to_run_exec ) : mod = ast . Module ( [ node ] ) code = self . compile ( mod , cell_name , "exec" ) if self . run_code ( code ) : return True for i , node in enumerate ( to_run_interactive ) : mod = ast . Interactive ( [ node ] ) code = self . compile ( mod , cell_name , "single" ) if self . run_code ( code ) : return True # Flush softspace if softspace ( sys . stdout , 0 ) : print except : # It's possible to have exceptions raised here, typically by # compilation of odd code (such as a naked 'return' outside a # function) that did parse but isn't valid. Typically the exception # is a SyntaxError, but it's safest just to catch anything and show # the user a traceback. # We do only one try/except outside the loop to minimize the impact # on runtime, and also because if any node in the node list is # broken, we should stop execution completely. self . showtraceback ( ) return False
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).
        interactivity : str
          'all', 'last', 'last_expr' 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. Other values
          for this parameter will raise a ValueError.
Run a sequence of AST nodes . The execution mode depends on the interactivity parameter .