##// END OF EJS Templates
Update some print statements in the docs
Thomas Kluyver -
Show More
@@ -181,11 +181,11 b' magic, a cell one and one that works in both modes, using just plain functions:'
181 181
182 182 from IPython.core.magic import (register_line_magic, register_cell_magic,
183 183 register_line_cell_magic)
184
184
185 185 @register_line_magic
186 186 def lmagic(line):
187 187 "my line magic"
188 return line
188 return line
189 189
190 190 @register_cell_magic
191 191 def cmagic(line, cell):
@@ -195,11 +195,11 b' magic, a cell one and one that works in both modes, using just plain functions:'
195 195 @register_line_cell_magic
196 196 def lcmagic(line, cell=None):
197 197 "Magic that works both as %lcmagic and as %%lcmagic"
198 if cell is None:
199 print "Called as line magic"
200 return line
201 else:
202 print "Called as cell magic"
198 if cell is None:
199 print("Called as line magic")
200 return line
201 else:
202 print("Called as cell magic")
203 203 return line, cell
204 204
205 205 # We delete these to avoid name conflicts for automagic to work
@@ -212,10 +212,11 b' potentially hold state in between calls, and that have full access to the main'
212 212 IPython object:
213 213
214 214 .. sourcecode:: python
215
215
216 216 # This code can be put in any Python module, it does not require IPython
217 217 # itself to be running already. It only creates the magics subclass but
218 218 # doesn't instantiate it yet.
219 from __future__ import print_function
219 220 from IPython.core.magic import (Magics, magics_class, line_magic,
220 221 cell_magic, line_cell_magic)
221 222
@@ -226,8 +227,8 b' IPython object:'
226 227 @line_magic
227 228 def lmagic(self, line):
228 229 "my line magic"
229 print "Full access to the main IPython object:", self.shell
230 print "Variables in the user namespace:", self.shell.user_ns.keys()
230 print("Full access to the main IPython object:", self.shell)
231 print("Variables in the user namespace:", list(self.shell.user_ns.keys()))
231 232 return line
232 233
233 234 @cell_magic
@@ -239,10 +240,10 b' IPython object:'
239 240 def lcmagic(self, line, cell=None):
240 241 "Magic that works both as %lcmagic and as %%lcmagic"
241 242 if cell is None:
242 print "Called as line magic"
243 print("Called as line magic")
243 244 return line
244 245 else:
245 print "Called as cell magic"
246 print("Called as cell magic")
246 247 return line, cell
247 248
248 249
@@ -259,11 +260,11 b' additional state, then you should always call the parent constructor and'
259 260 instantiate the class yourself before registration:
260 261
261 262 .. sourcecode:: python
262
263
263 264 @magics_class
264 265 class StatefulMagics(Magics):
265 266 "Magics that hold additional state"
266
267
267 268 def __init__(self, shell, data):
268 269 # You must call the parent constructor
269 270 super(StatefulMagics, self).__init__(shell)
@@ -288,8 +289,8 b' follows:'
288 289 .. sourcecode:: python
289 290
290 291 def func(self, line):
291 print "Line magic called with line:", line
292 print "IPython object:", self.shell
292 print("Line magic called with line:", line)
293 print("IPython object:", self.shell)
293 294
294 295 ip = get_ipython()
295 296 # Declare this function as the magic %mycommand
@@ -961,7 +962,7 b' standard Python tutorial::'
961 962 In [3]: ... a, b = 0, 1
962 963
963 964 In [4]: >>> while b < 10:
964 ...: ... print b
965 ...: ... print(b)
965 966 ...: ... a, b = b, a+b
966 967 ...:
967 968 1
@@ -62,7 +62,7 b' mechanism, this is automatically stored::'
62 62
63 63 hello - this is a temporary file
64 64
65 Out[1]: "print 'hello - this is a temporary file'\n"
65 Out[1]: "print('hello - this is a temporary file')\n"
66 66
67 67 Now, if you call ``%edit -p``, IPython tries to open an editor with the
68 68 same data as the last time you used %edit. So if you haven't used %edit
@@ -82,7 +82,7 b' Continuing with the example above, this should illustrate this idea::'
82 82
83 83 hello - now I made some changes
84 84
85 Out[2]: "print 'hello - now I made some changes'\n"
85 Out[2]: "print('hello - now I made some changes')\n"
86 86
87 87 In [3]: edit _1
88 88
@@ -94,7 +94,7 b' Continuing with the example above, this should illustrate this idea::'
94 94
95 95 IPython version control at work :)
96 96
97 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
97 Out[3]: "print('hello - this is a temporary file')\nprint('IPython version control at work :)')\n"
98 98
99 99
100 100 This section was written after a contribution by Alexander Belchenko on
General Comments 0
You need to be logged in to leave comments. Login now