From e5603e18ce228972e00e81716c143ae0efa2f75f Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 6 Jan 2014 12:03:41 -0800 Subject: [PATCH 1/2] Improve Python 3 compatibility in example notebooks --- examples/notebooks/Frontend-Kernel Model.ipynb | 5 ++--- examples/notebooks/Importing Notebooks.ipynb | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/notebooks/Frontend-Kernel Model.ipynb b/examples/notebooks/Frontend-Kernel Model.ipynb index 249788b6a..fb343b655 100644 --- a/examples/notebooks/Frontend-Kernel Model.ipynb +++ b/examples/notebooks/Frontend-Kernel Model.ipynb @@ -153,9 +153,8 @@ "collapsed": false, "input": [ "# Python 3 compat\n", - "try:\n", - " raw_input\n", - "except NameError:\n", + "import sys\n", + "if sys.version_info[0] >= 3:\n", " raw_input = input" ], "language": "python", diff --git a/examples/notebooks/Importing Notebooks.ipynb b/examples/notebooks/Importing Notebooks.ipynb index da7914e9a..d423b3fc1 100644 --- a/examples/notebooks/Importing Notebooks.ipynb +++ b/examples/notebooks/Importing Notebooks.ipynb @@ -157,7 +157,7 @@ " # transform the input to executable Python\n", " code = self.shell.input_transformer_manager.transform_cell(cell.input)\n", " # run the code in themodule\n", - " exec code in mod.__dict__\n", + " exec(code, mod.__dict__)\n", " finally:\n", " self.shell.user_ns = save_user_ns\n", " return mod\n" From 1e21f3295e700ade54a88d4ade5a776c5f86a970 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 6 Jan 2014 12:15:18 -0800 Subject: [PATCH 2/2] Polish test notebook --- examples/tests/Test Output Callbacks.ipynb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/tests/Test Output Callbacks.ipynb b/examples/tests/Test Output Callbacks.ipynb index ce2bfe87b..528bcdc7f 100644 --- a/examples/tests/Test Output Callbacks.ipynb +++ b/examples/tests/Test Output Callbacks.ipynb @@ -29,7 +29,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "print 'hi'" + "print('hi')" ], "language": "python", "metadata": {}, @@ -180,7 +180,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "# press tab after parentheses\n", + "# press shift-tab after parentheses\n", "int(" ], "language": "python", @@ -199,7 +199,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "# pres tab after f\n", + "# press tab after f\n", "f" ], "language": "python", @@ -218,7 +218,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "import sys\n", + "import sys, time\n", "from IPython.display import clear_output" ], "language": "python", @@ -232,7 +232,7 @@ "for i in range(10):\n", " clear_output()\n", " time.sleep(0.25)\n", - " print i\n", + " print(i)\n", " sys.stdout.flush()\n", " time.sleep(0.25)\n" ], @@ -247,7 +247,7 @@ "for i in range(10):\n", " clear_output(wait=True)\n", " time.sleep(0.25)\n", - " print i\n", + " print(i)\n", " sys.stdout.flush()\n" ], "language": "python",