def safe_execfile_ipy(self, fname, shell_futures=False, raise_exceptions=False):
    'Like safe_execfile, but for .ipy or .ipynb files with IPython syntax.\n\n        Parameters\n        ----------\n        fname : str\n            The name of the file to execute.  The filename must have a\n            .ipy or .ipynb extension.\n        shell_futures : bool (False)\n            If True, the code will share future statements with the interactive\n            shell. It will both be affected by previous __future__ imports, and\n            any __future__ imports in the code will affect the shell. If False,\n            __future__ imports are not shared in either direction.\n        raise_exceptions : bool (False)\n            If True raise exceptions everywhere.  Meant for testing.\n        '
    fname = Path(fname).expanduser().resolve()
    try:
        with fname.open('rb'):
            pass
    except:
        warn(('Could not open file <%s> for safe execution.' % fname))
        return
    dname = str(fname.parent)

    def get_cells():
        'generator for sequence of code blocks to run'
        if (fname.suffix == '.ipynb'):
            from nbformat import read
            nb = read(fname, as_version=4)
            if (not nb.cells):
                return
            for cell in nb.cells:
                if (cell.cell_type == 'code'):
                    (yield cell.source)
        else:
            (yield fname.read_text(encoding='utf-8'))
    with prepended_to_syspath(dname):
        try:
            for cell in get_cells():
                result = self.run_cell(cell, silent=True, shell_futures=shell_futures)
                if raise_exceptions:
                    result.raise_error()
                elif (not result.success):
                    break
        except:
            if raise_exceptions:
                raise
            self.showtraceback()
            warn(('Unknown failure executing file: <%s>' % fname))
Like safe_execfile, but for .ipy or .ipynb files with IPython syntax.

Parameters
----------
fname : str
    The name of the file to execute.  The filename must have a
    .ipy or .ipynb extension.
shell_futures : bool (False)
    If True, the code will share future statements with the interactive
    shell. It will both be affected by previous __future__ imports, and
    any __future__ imports in the code will affect the shell. If False,
    __future__ imports are not shared in either direction.
raise_exceptions : bool (False)
    If True raise exceptions everywhere.  Meant for testing.
def safe_execfile_ipy(self, fname, shell_futures=False, raise_exceptions=False):
    'Like safe_execfile, but for .ipy or .ipynb files with IPython syntax.\n\n        Parameters\n        ----------\n        fname : str\n            The name of the file to execute.  The filename must have a\n            .ipy or .ipynb extension.\n        shell_futures : bool (False)\n            If True, the code will share future statements with the interactive\n            shell. It will both be affected by previous __future__ imports, and\n            any __future__ imports in the code will affect the shell. If False,\n            __future__ imports are not shared in either direction.\n        raise_exceptions : bool (False)\n            If True raise exceptions everywhere.  Meant for testing.\n        '
    fname = Path(fname).expanduser().resolve()
    try:
        with fname.open('rb'):
            pass
    except:
        warn(('Could not open file <%s> for safe execution.' % fname))
        return
    dname = str(fname.parent)

    def get_cells():
        'generator for sequence of code blocks to run'
        if (fname.suffix == '.ipynb'):
            from nbformat import read
            nb = read(fname, as_version=4)
            if (not nb.cells):
                return
            for cell in nb.cells:
                if (cell.cell_type == 'code'):
                    (yield cell.source)
        else:
            (yield fname.read_text(encoding='utf-8'))
    with prepended_to_syspath(dname):
        try:
            for cell in get_cells():
                result = self.run_cell(cell, silent=True, shell_futures=shell_futures)
                if raise_exceptions:
                    result.raise_error()
                elif (not result.success):
                    break
        except:
            if raise_exceptions:
                raise
            self.showtraceback()
            warn(('Unknown failure executing file: <%s>' % fname))