diff --git a/docs/source/interactive/reference.rst b/docs/source/interactive/reference.rst index 8571e18..dd64825 100644 --- a/docs/source/interactive/reference.rst +++ b/docs/source/interactive/reference.rst @@ -181,11 +181,11 @@ magic, a cell one and one that works in both modes, using just plain functions: from IPython.core.magic import (register_line_magic, register_cell_magic, register_line_cell_magic) - + @register_line_magic def lmagic(line): "my line magic" - return line + return line @register_cell_magic def cmagic(line, cell): @@ -195,11 +195,11 @@ magic, a cell one and one that works in both modes, using just plain functions: @register_line_cell_magic def lcmagic(line, cell=None): "Magic that works both as %lcmagic and as %%lcmagic" - if cell is None: - print "Called as line magic" - return line - else: - print "Called as cell magic" + if cell is None: + print("Called as line magic") + return line + else: + print("Called as cell magic") return line, cell # We delete these to avoid name conflicts for automagic to work @@ -212,10 +212,11 @@ potentially hold state in between calls, and that have full access to the main IPython object: .. sourcecode:: python - + # This code can be put in any Python module, it does not require IPython # itself to be running already. It only creates the magics subclass but # doesn't instantiate it yet. + from __future__ import print_function from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic, line_cell_magic) @@ -226,8 +227,8 @@ IPython object: @line_magic def lmagic(self, line): "my line magic" - print "Full access to the main IPython object:", self.shell - print "Variables in the user namespace:", self.shell.user_ns.keys() + print("Full access to the main IPython object:", self.shell) + print("Variables in the user namespace:", list(self.shell.user_ns.keys())) return line @cell_magic @@ -239,10 +240,10 @@ IPython object: def lcmagic(self, line, cell=None): "Magic that works both as %lcmagic and as %%lcmagic" if cell is None: - print "Called as line magic" + print("Called as line magic") return line else: - print "Called as cell magic" + print("Called as cell magic") return line, cell @@ -259,11 +260,11 @@ additional state, then you should always call the parent constructor and instantiate the class yourself before registration: .. sourcecode:: python - + @magics_class class StatefulMagics(Magics): "Magics that hold additional state" - + def __init__(self, shell, data): # You must call the parent constructor super(StatefulMagics, self).__init__(shell) @@ -288,8 +289,8 @@ follows: .. sourcecode:: python def func(self, line): - print "Line magic called with line:", line - print "IPython object:", self.shell + print("Line magic called with line:", line) + print("IPython object:", self.shell) ip = get_ipython() # Declare this function as the magic %mycommand @@ -961,7 +962,7 @@ standard Python tutorial:: In [3]: ... a, b = 0, 1 In [4]: >>> while b < 10: - ...: ... print b + ...: ... print(b) ...: ... a, b = b, a+b ...: 1 diff --git a/docs/source/interactive/tips.rst b/docs/source/interactive/tips.rst index be08f68..c6cf3cb 100644 --- a/docs/source/interactive/tips.rst +++ b/docs/source/interactive/tips.rst @@ -62,7 +62,7 @@ mechanism, this is automatically stored:: hello - this is a temporary file - Out[1]: "print 'hello - this is a temporary file'\n" + Out[1]: "print('hello - this is a temporary file')\n" Now, if you call ``%edit -p``, IPython tries to open an editor with the same data as the last time you used %edit. So if you haven't used %edit @@ -82,7 +82,7 @@ Continuing with the example above, this should illustrate this idea:: hello - now I made some changes - Out[2]: "print 'hello - now I made some changes'\n" + Out[2]: "print('hello - now I made some changes')\n" In [3]: edit _1 @@ -94,7 +94,7 @@ Continuing with the example above, this should illustrate this idea:: IPython version control at work :) - Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n" + Out[3]: "print('hello - this is a temporary file')\nprint('IPython version control at work :)')\n" This section was written after a contribution by Alexander Belchenko on diff --git a/examples/core/appconfig.py b/examples/core/appconfig.py index a6b41c1..c2e4d26 100644 --- a/examples/core/appconfig.py +++ b/examples/core/appconfig.py @@ -30,8 +30,6 @@ When the config attribute of an Application is updated, it will fire all of the trait's events for all of the config=True attributes. """ -import sys - from IPython.config.configurable import Configurable from IPython.config.application import Application from IPython.utils.traitlets import ( @@ -87,8 +85,8 @@ class MyApp(Application): self.init_bar() def start(self): - print "app.config:" - print self.config + print("app.config:") + print(self.config) def main(): diff --git a/examples/core/ipython-get-history.py b/examples/core/ipython-get-history.py index d6d51ec..3768aea 100755 --- a/examples/core/ipython-get-history.py +++ b/examples/core/ipython-get-history.py @@ -17,7 +17,6 @@ to build much more flexible and powerful tools to browse and pull from the history database. """ import sys -import codecs from IPython.core.history import HistoryAccessor @@ -34,5 +33,5 @@ dest.write("# coding: utf-8\n") hist = HistoryAccessor() for session, lineno, cell in hist.get_range(session=session_number, raw=raw): - # To use this in Python 3, remove the .encode() here: - dest.write(cell.encode('utf-8') + '\n') + cell = cell.encode('utf-8') # This line is only needed on Python 2. + dest.write(cell + '\n') diff --git a/examples/inprocess/embedded_qtconsole.py b/examples/inprocess/embedded_qtconsole.py index 5fe6a1a..3fc6629 100644 --- a/examples/inprocess/embedded_qtconsole.py +++ b/examples/inprocess/embedded_qtconsole.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os from IPython.qt.console.rich_ipython_widget import RichIPythonWidget @@ -6,7 +7,7 @@ from IPython.lib import guisupport def print_process_id(): - print 'Process ID is:', os.getpid() + print('Process ID is:', os.getpid()) def main(): diff --git a/examples/inprocess/embedded_terminal.py b/examples/inprocess/embedded_terminal.py index e42105b..a295c0a 100644 --- a/examples/inprocess/embedded_terminal.py +++ b/examples/inprocess/embedded_terminal.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os from IPython.kernel.inprocess import InProcessKernelManager @@ -5,7 +6,7 @@ from IPython.terminal.console.interactiveshell import ZMQTerminalInteractiveShel def print_process_id(): - print 'Process ID is:', os.getpid() + print('Process ID is:', os.getpid()) def main(): diff --git a/examples/lib/BackgroundJobs.ipynb b/examples/lib/BackgroundJobs.ipynb index 595886d..89afacb 100644 --- a/examples/lib/BackgroundJobs.ipynb +++ b/examples/lib/BackgroundJobs.ipynb @@ -1,6 +1,6 @@ { "metadata": { - "name": "BackgroundJobs" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -20,6 +20,7 @@ "cell_type": "code", "collapsed": false, "input": [ + "from __future__ import print_function\n", "from IPython.lib import backgroundjobs as bg\n", "\n", "import sys\n", @@ -39,15 +40,15 @@ "def printfunc(interval=1, reps=5):\n", " for n in range(reps):\n", " time.sleep(interval)\n", - " print 'In the background...', n\n", + " print('In the background...', n)\n", " sys.stdout.flush()\n", - " print 'All done!'\n", + " print('All done!')\n", " sys.stdout.flush()" ], "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 35 + "prompt_number": 1 }, { "cell_type": "markdown", @@ -87,37 +88,9 @@ "Starting job # 4 in a separate thread.\n", "Starting job # 5 in a separate thread.\n" ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In the background... 0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In the background... 1\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In the background... 2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "All done!\n" - ] } ], - "prompt_number": 36 + "prompt_number": 2 }, { "cell_type": "markdown", @@ -139,19 +112,27 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Completed jobs:\n", - "0 : <function sleepfunc at 0x30e1578>\n", - "2 : <function sleepfunc at 0x30e1578>\n", + "In the background... 0\n", + "Running jobs:" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "0 : \n", + "2 : \n", "3 : printfunc(1,3)\n", + "5 : \n", "\n", "Dead jobs:\n", - "4 : <function diefunc at 0x304d488>\n", - "5 : <function diefunc at 0x304d488>\n", + "4 : \n", "\n" ] } ], - "prompt_number": 37 + "prompt_number": 3 }, { "cell_type": "markdown", @@ -170,8 +151,18 @@ ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 43 + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In the background... 1\n", + "In the background... 2\n", + "All done!\n" + ] + } + ], + "prompt_number": 4 }, { "cell_type": "markdown", @@ -193,29 +184,15 @@ "metadata": {}, "outputs": [ { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Status of diejob1: Dead (Exception), call jobs.traceback() for details\n", - "---------------------------------------------------------------------------\n", - "Exception Traceback (most recent call last)\n", - "/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py in call(self)\n", - " 462 \n", - " 463 def call(self):\n", - "--> 464 return self.func(*self.args, **self.kwargs)\n", - "\n", - "/home/fperez/ipython/ipython/docs/examples/lib/<ipython-input-15-54795a097787> in diefunc(interval, *a, **kw)\n", - " 14 def diefunc(interval=2, *a, **kw):\n", - " 15 time.sleep(interval)\n", - "---> 16 raise Exception("Dead job with interval %s" % interval)\n", - " 17 \n", - " 18 def printfunc(interval=1, reps=5):\n", - "\n", - "Exception: Dead job with interval 1\n" + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 1)", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m print \"Status of diejob1:\", diejob1.status\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" ] } ], - "prompt_number": 34 + "prompt_number": 5 }, { "cell_type": "markdown", @@ -237,44 +214,44 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Traceback for: <BackgroundJob #4: <function diefunc at 0x30df758>>\n", - "---------------------------------------------------------------------------\n", - "Exception Traceback (most recent call last)\n", - "/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py in call(self)\n", - " 462 \n", - " 463 def call(self):\n", - "--> 464 return self.func(*self.args, **self.kwargs)\n", + "Traceback for: >\n", + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n", + "\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n", + "\u001b[1;32m/home/takluyver/.local/lib/python3.3/site-packages/IPython/lib/backgroundjobs.py\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n", + "\u001b[0;32m 489\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 490\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m--> 491\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mdiefunc\u001b[1;34m(interval, *a, **kw)\u001b[0m\n", + "\u001b[0;32m 14\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdiefunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 15\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m---> 16\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Dead job with interval %s\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\u001b[0;32m 17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 18\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mprintfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreps\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\n", - "/home/fperez/ipython/ipython/docs/examples/lib/<ipython-input-15-54795a097787> in diefunc(interval, *a, **kw)\n", - " 14 def diefunc(interval=2, *a, **kw):\n", - " 15 time.sleep(interval)\n", - "---> 16 raise Exception("Dead job with interval %s" % interval)\n", - " 17 \n", - " 18 def printfunc(interval=1, reps=5):\n", + "\u001b[1;31mException\u001b[0m: Dead job with interval 1\n", "\n", - "Exception: Dead job with interval 1\n", + "Traceback for: >\n", + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n", + "\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n", + "\u001b[1;32m/home/takluyver/.local/lib/python3.3/site-packages/IPython/lib/backgroundjobs.py\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n", + "\u001b[0;32m 489\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 490\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m--> 491\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mdiefunc\u001b[1;34m(interval, *a, **kw)\u001b[0m\n", + "\u001b[0;32m 14\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdiefunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 15\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m---> 16\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Dead job with interval %s\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\u001b[0;32m 17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 18\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mprintfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreps\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\n", - "Traceback for: <BackgroundJob #5: <function diefunc at 0x30df758>>\n", - "---------------------------------------------------------------------------\n", - "Exception Traceback (most recent call last)\n", - "/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py in call(self)\n", - " 462 \n", - " 463 def call(self):\n", - "--> 464 return self.func(*self.args, **self.kwargs)\n", - "\n", - "/home/fperez/ipython/ipython/docs/examples/lib/<ipython-input-15-54795a097787> in diefunc(interval, *a, **kw)\n", - " 14 def diefunc(interval=2, *a, **kw):\n", - " 15 time.sleep(interval)\n", - "---> 16 raise Exception("Dead job with interval %s" % interval)\n", - " 17 \n", - " 18 def printfunc(interval=1, reps=5):\n", - "\n", - "Exception: Dead job with interval 2\n", + "\u001b[1;31mException\u001b[0m: Dead job with interval 2\n", "\n" ] } ], - "prompt_number": 33 + "prompt_number": 6 }, { "cell_type": "markdown", @@ -296,11 +273,12 @@ "output_type": "stream", "stream": "stdout", "text": [ - "No jobs to flush.\n" + "Flushing 3 Completed jobs.\n", + "Flushing 2 Dead jobs.\n" ] } ], - "prompt_number": 25 + "prompt_number": 7 }, { "cell_type": "markdown", @@ -318,7 +296,7 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 27 + "prompt_number": 8 }, { "cell_type": "markdown", @@ -332,10 +310,10 @@ "collapsed": false, "input": [ "j = jobs.new(sleepfunc, 2)\n", - "print \"Will wait for j now...\"\n", + "print(\"Will wait for j now...\")\n", "sys.stdout.flush()\n", "j.join()\n", - "print \"Result from j:\"\n", + "print(\"Result from j:\")\n", "j.result" ], "language": "python", @@ -345,7 +323,7 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Starting job # 7 in a separate thread.\n", + "Starting job # 0 in a separate thread.\n", "Will wait for j now...\n" ] }, @@ -357,14 +335,15 @@ ] }, { + "metadata": {}, "output_type": "pyout", - "prompt_number": 46, + "prompt_number": 9, "text": [ - "{'args': (), 'interval': 2, 'kwargs': {}}" + "{'kwargs': {}, 'args': (), 'interval': 2}" ] } ], - "prompt_number": 46 + "prompt_number": 9 }, { "cell_type": "code", diff --git a/examples/lib/gui-qt.py b/examples/lib/gui-qt.py index 13e4d27..abb6fb8 100755 --- a/examples/lib/gui-qt.py +++ b/examples/lib/gui-qt.py @@ -10,7 +10,6 @@ In [6]: %run gui-qt.py Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/ """ -import sys from PyQt4 import QtGui, QtCore class SimpleWindow(QtGui.QWidget): diff --git a/examples/lib/gui-tk.py b/examples/lib/gui-tk.py index beb8677..681e003 100755 --- a/examples/lib/gui-tk.py +++ b/examples/lib/gui-tk.py @@ -8,7 +8,10 @@ In [5]: %gui tk In [6]: %run gui-tk.py """ -from Tkinter import * +try: + from tkinter import * # Python 3 +except ImportError: + from Tkinter import * # Python 2 class MyApp: diff --git a/examples/lib/internal_ipkernel.py b/examples/lib/internal_ipkernel.py index 862bae2..d3ee57c 100644 --- a/examples/lib/internal_ipkernel.py +++ b/examples/lib/internal_ipkernel.py @@ -2,7 +2,6 @@ # Imports #----------------------------------------------------------------------------- -import subprocess import sys from IPython.lib.kernel import connect_qtconsole @@ -42,7 +41,7 @@ class InternalIPKernel(object): def print_namespace(self, evt=None): print("\n***Variables in User namespace***") - for k, v in self.namespace.iteritems(): + for k, v in self.namespace.items(): if k not in self._init_keys and not k.startswith('_'): print('%s -> %r' % (k, v)) sys.stdout.flush() diff --git a/examples/notebooks/Frontend-Kernel Model.ipynb b/examples/notebooks/Frontend-Kernel Model.ipynb index 249788b..fb343b6 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 da7914e..d423b3f 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" diff --git a/examples/notebooks/Part 5 - Rich Display System.ipynb b/examples/notebooks/Part 5 - Rich Display System.ipynb index 257e762..19e9efa 100644 --- a/examples/notebooks/Part 5 - Rich Display System.ipynb +++ b/examples/notebooks/Part 5 - Rich Display System.ipynb @@ -989,24 +989,6 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "By default, `DataFrames` will be represented as text; to enable HTML representations we need to set a print option:" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "pandas.core.format.set_printoptions(notebook_repr_html=True)" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 9 - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ "Here is a small amount of stock data for APPL:" ] }, diff --git a/examples/parallel/Parallel Magics.ipynb b/examples/parallel/Parallel Magics.ipynb index 31b6b76..e54255a 100644 --- a/examples/parallel/Parallel Magics.ipynb +++ b/examples/parallel/Parallel Magics.ipynb @@ -67,7 +67,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "%px print a" + "%px print(a)" ], "language": "python", "metadata": {}, @@ -98,7 +98,8 @@ "cell_type": "code", "collapsed": false, "input": [ - "%px print >> sys.stderr, \"ERROR\"" + "%px from __future__ import print_function\n", + "%px print(\"ERROR\", file=sys.stderr)" ], "language": "python", "metadata": {}, @@ -208,7 +209,7 @@ "%%px --noblock\n", "x = np.linspace(0,np.pi,1000)\n", "for n in range(id,12, stride):\n", - " print n\n", + " print(n)\n", " plt.plot(x,np.sin(n*x))\n", "plt.title(\"Plot %i\" % id)" ], @@ -248,7 +249,7 @@ "%%px --group-outputs=engine\n", "x = np.linspace(0,np.pi,1000)\n", "for n in range(id+1,12, stride):\n", - " print n\n", + " print(n)\n", " plt.figure()\n", " plt.plot(x,np.sin(n*x))\n", " plt.title(\"Plot %i\" % n)" @@ -296,6 +297,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "from __future__ import print_function\n", + "\n", "def generate_output():\n", " \"\"\"function for testing output\n", " \n", @@ -305,13 +308,13 @@ " import sys,os\n", " from IPython.display import display, HTML, Math\n", " \n", - " print \"stdout\"\n", - " print >> sys.stderr, \"stderr\"\n", + " print(\"stdout\")\n", + " print(\"stderr\", file=sys.stderr)\n", " \n", " display(HTML(\"HTML\"))\n", " \n", - " print \"stdout2\"\n", - " print >> sys.stderr, \"stderr2\"\n", + " print(\"stdout2\")\n", + " print(\"stderr2\", file=sys.stderr)\n", " \n", " display(Math(r\"\\alpha=\\beta\"))\n", " \n", @@ -461,7 +464,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As of IPython 0.14, you can instruct `%%px` to also execute the cell locally.\n", + "As of IPython 1.0, you can instruct `%%px` to also execute the cell locally.\n", "This is useful for interactive definitions,\n", "or if you want to load a data source everywhere,\n", "not just on the engines." @@ -474,7 +477,7 @@ "%%px --local\n", "import os\n", "thispid = os.getpid()\n", - "print thispid" + "print(thispid)" ], "language": "python", "metadata": {}, diff --git a/examples/parallel/helloworld.ipynb b/examples/parallel/helloworld.ipynb index 5aeed3c..582da63 100644 --- a/examples/parallel/helloworld.ipynb +++ b/examples/parallel/helloworld.ipynb @@ -1,6 +1,6 @@ { "metadata": { - "name": "helloworld" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -20,6 +20,7 @@ "cell_type": "code", "collapsed": true, "input": [ + "from __future__ import print_function\n", "from IPython.parallel import Client" ], "language": "python", @@ -69,8 +70,8 @@ "cell_type": "code", "collapsed": false, "input": [ - "print \"Submitted tasks:\", hello.msg_ids + world.msg_ids\n", - "print hello.get(), world.get()" + "print(\"Submitted tasks:\", hello.msg_ids + world.msg_ids)\n", + "print(hello.get(), world.get())" ], "language": "python", "metadata": {}, diff --git a/examples/parallel/task1.ipynb b/examples/parallel/task1.ipynb index 27ae077..b4b65c8 100644 --- a/examples/parallel/task1.ipynb +++ b/examples/parallel/task1.ipynb @@ -18,6 +18,7 @@ "cell_type": "code", "collapsed": true, "input": [ + "from __future__ import print_function\n", "from IPython.parallel import Client" ], "language": "python", @@ -110,7 +111,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "print \"a, b, c: \", ar.get()" + "print(\"a, b, c: \", ar.get())" ], "language": "python", "metadata": {}, diff --git a/examples/parallel/taskmap.ipynb b/examples/parallel/taskmap.ipynb index ad15260..80661b8 100644 --- a/examples/parallel/taskmap.ipynb +++ b/examples/parallel/taskmap.ipynb @@ -1,6 +1,6 @@ { "metadata": { - "name": "taskmap" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -18,6 +18,7 @@ "cell_type": "code", "collapsed": true, "input": [ + "from __future__ import print_function\n", "from IPython.parallel import Client" ], "language": "python", @@ -42,7 +43,7 @@ "collapsed": false, "input": [ "result = v.map(lambda x: 2*x, range(10))\n", - "print \"Simple, default map: \", list(result)" + "print(\"Simple, default map: \", list(result))" ], "language": "python", "metadata": {}, @@ -69,9 +70,9 @@ "collapsed": false, "input": [ "ar = v.map_async(lambda x: 2*x, range(10))\n", - "print \"Submitted tasks, got ids: \", ar.msg_ids\n", + "print(\"Submitted tasks, got ids: \", ar.msg_ids)\n", "result = ar.get()\n", - "print \"Using a mapper: \", result" + "print(\"Using a mapper: \", result)" ], "language": "python", "metadata": {}, @@ -95,7 +96,7 @@ "def f(x): return 2*x\n", "\n", "result = f.map(range(10))\n", - "print \"Using a parallel function: \", result" + "print(\"Using a parallel function: \", result)" ], "language": "python", "metadata": {}, diff --git a/examples/tests/Test Output Callbacks.ipynb b/examples/tests/Test Output Callbacks.ipynb index ce2bfe8..528bcdc 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",