Merge pull request #1420 from yuvallanger/import-notebooks-patch

Make Importing Notebooks guide work again.
pull/1429/head
Thomas Kluyver 10 years ago
commit 27a4bf8e4b

@ -40,7 +40,7 @@
"outputs": [],
"source": [
"from IPython import get_ipython\n",
"from IPython.nbformat import current\n",
"from nbformat import read\n",
"from IPython.core.interactiveshell import InteractiveShell"
]
},
@ -130,7 +130,7 @@
" \n",
" # load the notebook object\n",
" with io.open(path, 'r', encoding='utf-8') as f:\n",
" nb = current.read(f, 'json')\n",
" nb = read(f, 4)\n",
" \n",
" \n",
" # create the module and add it to sys.modules\n",
@ -148,10 +148,10 @@
" self.shell.user_ns = mod.__dict__\n",
" \n",
" try:\n",
" for cell in nb.worksheets[0].cells:\n",
" if cell.cell_type == 'code' and cell.language == 'python':\n",
" for cell in nb.cells:\n",
" if cell.cell_type == 'code':\n",
" # transform the input to executable Python\n",
" code = self.shell.input_transformer_manager.transform_cell(cell.input)\n",
" code = self.shell.input_transformer_manager.transform_cell(cell.source)\n",
" # run the code in themodule\n",
" exec(code, mod.__dict__)\n",
" finally:\n",
@ -261,7 +261,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"So I should be able to `import nbimp.mynotebook`.\n"
"So I should be able to `import nbpackage.mynotebook`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import nbpackage.mynotebook"
]
},
{
@ -316,12 +327,12 @@
"def show_notebook(fname):\n",
" \"\"\"display a short summary of the cells of a notebook\"\"\"\n",
" with io.open(fname, 'r', encoding='utf-8') as f:\n",
" nb = current.read(f, 'json')\n",
" nb = read(f, 4)\n",
" html = []\n",
" for cell in nb.worksheets[0].cells:\n",
" for cell in nb.cells:\n",
" html.append(\"<h4>%s cell</h4>\" % cell.cell_type)\n",
" if cell.cell_type == 'code':\n",
" html.append(highlight(cell.input, lexer, formatter))\n",
" html.append(highlight(cell.source, lexer, formatter))\n",
" else:\n",
" html.append(\"<pre>%s</pre>\" % cell.source)\n",
" display(HTML('\\n'.join(html)))\n",
@ -463,7 +474,7 @@
"outputs": [],
"source": [
"import shutil\n",
"from IPython.utils.path import get_ipython_package_dir\n",
"from IPython.paths import get_ipython_package_dir\n",
"\n",
"utils = os.path.join(get_ipython_package_dir(), 'utils')\n",
"shutil.copy(os.path.join(\"nbpackage\", \"mynotebook.ipynb\"),\n",
@ -515,7 +526,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.1+"
}
},
"nbformat": 4,

@ -61,7 +61,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.2"
"version": "3.5.1+"
}
},
"nbformat": 4,

Loading…
Cancel
Save