# Buggy code
def split_lines(nb):
    """split likely multiline text into lists of strings

    For file output more friendly to line-based VCS. ``rejoin_lines(nb)`` will
    reverse the effects of ``split_lines(nb)``.

    Used when writing JSON files.
    """
    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == "code":
                if "input" in cell and isinstance(cell.input, basestring):
                    cell.input = cell.input.splitlines()
                for output in cell.outputs:
                    for key in _multiline_outputs:
                        item = output.get(key, None)
                        if isinstance(item, basestring):
                            output[key] = item.splitlines()
            else:  # text, heading cell
                for key in ["source", "rendered"]:
                    item = cell.get(key, None)
                    if isinstance(item, basestring):
                        cell[key] = item.splitlines()
    return nb


# Traceback (TypeError)
%notebook -e foo.py
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/opt/source/packaging/pandas/pandas_build_virtenv/<ipython-input-245-d2b2edf081ed> in <module>()
----> 1 get_ipython().magic(u'notebook -e foo.py')

/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s, next_input)
1996                 self._magic_locals = sys._getframe(1).f_locals
1997             with self.builtin_trap:
-> 1998                 result = fn(magic_args)
1999             # Ensure we're not keeping object references around:

2000             self._magic_locals = {}

/usr/lib/python2.7/dist-packages/IPython/core/magic.pyc in magic_notebook(self, s)
3547                 cells.append(current.new_code_cell(prompt_number=prompt_number, input=input))
3548             worksheet = current.new_worksheet(cells=cells)
-> 3549             nb = current.new_notebook(name=name,worksheets=[worksheet])
3550             with open(fname, 'w') as f:
3551                 current.write(nb, f, format);

TypeError: new_notebook() got an unexpected keyword argument 'name'

# Fixed code
def split_lines(nb):
    """split likely multiline text into lists of strings

    For file output more friendly to line-based VCS. ``rejoin_lines(nb)`` will
    reverse the effects of ``split_lines(nb)``.

    Used when writing JSON files.
    """
    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == "code":
                if "input" in cell and isinstance(cell.input, basestring):
                    cell.input = (cell.input + "\n").splitlines()
                for output in cell.outputs:
                    for key in _multiline_outputs:
                        item = output.get(key, None)
                        if isinstance(item, basestring):
                            output[key] = (item + "\n").splitlines()
            else:  # text, heading cell
                for key in ["source", "rendered"]:
                    item = cell.get(key, None)
                    if isinstance(item, basestring):
                        cell[key] = (item + "\n").splitlines()
    return nb