From 5bdc2de4a00923f40f4427ed3945c4d537138cae 2014-01-06 21:05:33 From: Thomas Kluyver Date: 2014-01-06 21:05:33 Subject: [PATCH] Update some print statements in the docs --- 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