##// END OF EJS Templates
Merge pull request #4760 from takluyver/examples-py3compat...
Min RK -
r14082:608fd030 merge
parent child Browse files
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 from IPython.core.magic import (register_line_magic, register_cell_magic,
182 from IPython.core.magic import (register_line_magic, register_cell_magic,
183 register_line_cell_magic)
183 register_line_cell_magic)
184
184
185 @register_line_magic
185 @register_line_magic
186 def lmagic(line):
186 def lmagic(line):
187 "my line magic"
187 "my line magic"
188 return line
188 return line
189
189
190 @register_cell_magic
190 @register_cell_magic
191 def cmagic(line, cell):
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 @register_line_cell_magic
195 @register_line_cell_magic
196 def lcmagic(line, cell=None):
196 def lcmagic(line, cell=None):
197 "Magic that works both as %lcmagic and as %%lcmagic"
197 "Magic that works both as %lcmagic and as %%lcmagic"
198 if cell is None:
198 if cell is None:
199 print "Called as line magic"
199 print("Called as line magic")
200 return line
200 return line
201 else:
201 else:
202 print "Called as cell magic"
202 print("Called as cell magic")
203 return line, cell
203 return line, cell
204
204
205 # We delete these to avoid name conflicts for automagic to work
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 IPython object:
212 IPython object:
213
213
214 .. sourcecode:: python
214 .. sourcecode:: python
215
215
216 # This code can be put in any Python module, it does not require IPython
216 # This code can be put in any Python module, it does not require IPython
217 # itself to be running already. It only creates the magics subclass but
217 # itself to be running already. It only creates the magics subclass but
218 # doesn't instantiate it yet.
218 # doesn't instantiate it yet.
219 from __future__ import print_function
219 from IPython.core.magic import (Magics, magics_class, line_magic,
220 from IPython.core.magic import (Magics, magics_class, line_magic,
220 cell_magic, line_cell_magic)
221 cell_magic, line_cell_magic)
221
222
@@ -226,8 +227,8 b' IPython object:'
226 @line_magic
227 @line_magic
227 def lmagic(self, line):
228 def lmagic(self, line):
228 "my line magic"
229 "my line magic"
229 print "Full access to the main IPython object:", self.shell
230 print("Full access to the main IPython object:", self.shell)
230 print "Variables in the user namespace:", self.shell.user_ns.keys()
231 print("Variables in the user namespace:", list(self.shell.user_ns.keys()))
231 return line
232 return line
232
233
233 @cell_magic
234 @cell_magic
@@ -239,10 +240,10 b' IPython object:'
239 def lcmagic(self, line, cell=None):
240 def lcmagic(self, line, cell=None):
240 "Magic that works both as %lcmagic and as %%lcmagic"
241 "Magic that works both as %lcmagic and as %%lcmagic"
241 if cell is None:
242 if cell is None:
242 print "Called as line magic"
243 print("Called as line magic")
243 return line
244 return line
244 else:
245 else:
245 print "Called as cell magic"
246 print("Called as cell magic")
246 return line, cell
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 instantiate the class yourself before registration:
260 instantiate the class yourself before registration:
260
261
261 .. sourcecode:: python
262 .. sourcecode:: python
262
263
263 @magics_class
264 @magics_class
264 class StatefulMagics(Magics):
265 class StatefulMagics(Magics):
265 "Magics that hold additional state"
266 "Magics that hold additional state"
266
267
267 def __init__(self, shell, data):
268 def __init__(self, shell, data):
268 # You must call the parent constructor
269 # You must call the parent constructor
269 super(StatefulMagics, self).__init__(shell)
270 super(StatefulMagics, self).__init__(shell)
@@ -288,8 +289,8 b' follows:'
288 .. sourcecode:: python
289 .. sourcecode:: python
289
290
290 def func(self, line):
291 def func(self, line):
291 print "Line magic called with line:", line
292 print("Line magic called with line:", line)
292 print "IPython object:", self.shell
293 print("IPython object:", self.shell)
293
294
294 ip = get_ipython()
295 ip = get_ipython()
295 # Declare this function as the magic %mycommand
296 # Declare this function as the magic %mycommand
@@ -961,7 +962,7 b' standard Python tutorial::'
961 In [3]: ... a, b = 0, 1
962 In [3]: ... a, b = 0, 1
962
963
963 In [4]: >>> while b < 10:
964 In [4]: >>> while b < 10:
964 ...: ... print b
965 ...: ... print(b)
965 ...: ... a, b = b, a+b
966 ...: ... a, b = b, a+b
966 ...:
967 ...:
967 1
968 1
@@ -62,7 +62,7 b' mechanism, this is automatically stored::'
62
62
63 hello - this is a temporary file
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 Now, if you call ``%edit -p``, IPython tries to open an editor with the
67 Now, if you call ``%edit -p``, IPython tries to open an editor with the
68 same data as the last time you used %edit. So if you haven't used %edit
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 hello - now I made some changes
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 In [3]: edit _1
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 IPython version control at work :)
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 This section was written after a contribution by Alexander Belchenko on
100 This section was written after a contribution by Alexander Belchenko on
@@ -30,8 +30,6 b' When the config attribute of an Application is updated, it will fire all of'
30 the trait's events for all of the config=True attributes.
30 the trait's events for all of the config=True attributes.
31 """
31 """
32
32
33 import sys
34
35 from IPython.config.configurable import Configurable
33 from IPython.config.configurable import Configurable
36 from IPython.config.application import Application
34 from IPython.config.application import Application
37 from IPython.utils.traitlets import (
35 from IPython.utils.traitlets import (
@@ -87,8 +85,8 b' class MyApp(Application):'
87 self.init_bar()
85 self.init_bar()
88
86
89 def start(self):
87 def start(self):
90 print "app.config:"
88 print("app.config:")
91 print self.config
89 print(self.config)
92
90
93
91
94 def main():
92 def main():
@@ -17,7 +17,6 b' to build much more flexible and powerful tools to browse and pull from the'
17 history database.
17 history database.
18 """
18 """
19 import sys
19 import sys
20 import codecs
21
20
22 from IPython.core.history import HistoryAccessor
21 from IPython.core.history import HistoryAccessor
23
22
@@ -34,5 +33,5 b' dest.write("# coding: utf-8\\n")'
34 hist = HistoryAccessor()
33 hist = HistoryAccessor()
35
34
36 for session, lineno, cell in hist.get_range(session=session_number, raw=raw):
35 for session, lineno, cell in hist.get_range(session=session_number, raw=raw):
37 # To use this in Python 3, remove the .encode() here:
36 cell = cell.encode('utf-8') # This line is only needed on Python 2.
38 dest.write(cell.encode('utf-8') + '\n')
37 dest.write(cell + '\n')
@@ -1,3 +1,4 b''
1 from __future__ import print_function
1 import os
2 import os
2
3
3 from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
4 from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
@@ -6,7 +7,7 b' from IPython.lib import guisupport'
6
7
7
8
8 def print_process_id():
9 def print_process_id():
9 print 'Process ID is:', os.getpid()
10 print('Process ID is:', os.getpid())
10
11
11
12
12 def main():
13 def main():
@@ -1,3 +1,4 b''
1 from __future__ import print_function
1 import os
2 import os
2
3
3 from IPython.kernel.inprocess import InProcessKernelManager
4 from IPython.kernel.inprocess import InProcessKernelManager
@@ -5,7 +6,7 b' from IPython.terminal.console.interactiveshell import ZMQTerminalInteractiveShel'
5
6
6
7
7 def print_process_id():
8 def print_process_id():
8 print 'Process ID is:', os.getpid()
9 print('Process ID is:', os.getpid())
9
10
10
11
11 def main():
12 def main():
@@ -1,6 +1,6 b''
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "name": "BackgroundJobs"
3 "name": ""
4 },
4 },
5 "nbformat": 3,
5 "nbformat": 3,
6 "nbformat_minor": 0,
6 "nbformat_minor": 0,
@@ -20,6 +20,7 b''
20 "cell_type": "code",
20 "cell_type": "code",
21 "collapsed": false,
21 "collapsed": false,
22 "input": [
22 "input": [
23 "from __future__ import print_function\n",
23 "from IPython.lib import backgroundjobs as bg\n",
24 "from IPython.lib import backgroundjobs as bg\n",
24 "\n",
25 "\n",
25 "import sys\n",
26 "import sys\n",
@@ -39,15 +40,15 b''
39 "def printfunc(interval=1, reps=5):\n",
40 "def printfunc(interval=1, reps=5):\n",
40 " for n in range(reps):\n",
41 " for n in range(reps):\n",
41 " time.sleep(interval)\n",
42 " time.sleep(interval)\n",
42 " print 'In the background...', n\n",
43 " print('In the background...', n)\n",
43 " sys.stdout.flush()\n",
44 " sys.stdout.flush()\n",
44 " print 'All done!'\n",
45 " print('All done!')\n",
45 " sys.stdout.flush()"
46 " sys.stdout.flush()"
46 ],
47 ],
47 "language": "python",
48 "language": "python",
48 "metadata": {},
49 "metadata": {},
49 "outputs": [],
50 "outputs": [],
50 "prompt_number": 35
51 "prompt_number": 1
51 },
52 },
52 {
53 {
53 "cell_type": "markdown",
54 "cell_type": "markdown",
@@ -87,37 +88,9 b''
87 "Starting job # 4 in a separate thread.\n",
88 "Starting job # 4 in a separate thread.\n",
88 "Starting job # 5 in a separate thread.\n"
89 "Starting job # 5 in a separate thread.\n"
89 ]
90 ]
90 },
91 {
92 "output_type": "stream",
93 "stream": "stdout",
94 "text": [
95 "In the background... 0\n"
96 ]
97 },
98 {
99 "output_type": "stream",
100 "stream": "stdout",
101 "text": [
102 "In the background... 1\n"
103 ]
104 },
105 {
106 "output_type": "stream",
107 "stream": "stdout",
108 "text": [
109 "In the background... 2\n"
110 ]
111 },
112 {
113 "output_type": "stream",
114 "stream": "stdout",
115 "text": [
116 "All done!\n"
117 ]
118 }
91 }
119 ],
92 ],
120 "prompt_number": 36
93 "prompt_number": 2
121 },
94 },
122 {
95 {
123 "cell_type": "markdown",
96 "cell_type": "markdown",
@@ -139,19 +112,27 b''
139 "output_type": "stream",
112 "output_type": "stream",
140 "stream": "stdout",
113 "stream": "stdout",
141 "text": [
114 "text": [
142 "Completed jobs:\n",
115 "In the background... 0\n",
143 "0 : &lt;function sleepfunc at 0x30e1578&gt;\n",
116 "Running jobs:"
144 "2 : &lt;function sleepfunc at 0x30e1578&gt;\n",
117 ]
118 },
119 {
120 "output_type": "stream",
121 "stream": "stdout",
122 "text": [
123 "\n",
124 "0 : <function sleepfunc at 0x7f2a1c9963b0>\n",
125 "2 : <function sleepfunc at 0x7f2a1c9963b0>\n",
145 "3 : printfunc(1,3)\n",
126 "3 : printfunc(1,3)\n",
127 "5 : <function diefunc at 0x7f2a1c996440>\n",
146 "\n",
128 "\n",
147 "Dead jobs:\n",
129 "Dead jobs:\n",
148 "4 : &lt;function diefunc at 0x304d488&gt;\n",
130 "4 : <function diefunc at 0x7f2a1c996440>\n",
149 "5 : &lt;function diefunc at 0x304d488&gt;\n",
150 "\n"
131 "\n"
151 ]
132 ]
152 }
133 }
153 ],
134 ],
154 "prompt_number": 37
135 "prompt_number": 3
155 },
136 },
156 {
137 {
157 "cell_type": "markdown",
138 "cell_type": "markdown",
@@ -170,8 +151,18 b''
170 ],
151 ],
171 "language": "python",
152 "language": "python",
172 "metadata": {},
153 "metadata": {},
173 "outputs": [],
154 "outputs": [
174 "prompt_number": 43
155 {
156 "output_type": "stream",
157 "stream": "stdout",
158 "text": [
159 "In the background... 1\n",
160 "In the background... 2\n",
161 "All done!\n"
162 ]
163 }
164 ],
165 "prompt_number": 4
175 },
166 },
176 {
167 {
177 "cell_type": "markdown",
168 "cell_type": "markdown",
@@ -193,29 +184,15 b''
193 "metadata": {},
184 "metadata": {},
194 "outputs": [
185 "outputs": [
195 {
186 {
196 "output_type": "stream",
187 "ename": "SyntaxError",
197 "stream": "stdout",
188 "evalue": "invalid syntax (<ipython-input-5-a90bd59af669>, line 1)",
198 "text": [
189 "output_type": "pyerr",
199 "Status of diejob1: Dead (Exception), call jobs.traceback() for details\n",
190 "traceback": [
200 "<span class=\"ansired\">---------------------------------------------------------------------------</span>\n",
191 "\u001b[1;36m File \u001b[1;32m\"<ipython-input-5-a90bd59af669>\"\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"
201 "<span class=\"ansired\">Exception</span> Traceback (most recent call last)\n",
202 "<span class=\"ansigreen\">/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py</span> in <span class=\"ansicyan\">call</span><span class=\"ansiblue\">(self)</span>\n",
203 "<span class=\"ansigreen\"> 462</span> <span class=\"ansiyellow\"></span>\n",
204 "<span class=\"ansigreen\"> 463</span> <span class=\"ansigreen\">def</span> call<span class=\"ansiyellow\">(</span>self<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
205 "<span class=\"ansigreen\">--&gt; 464</span><span class=\"ansiyellow\"> </span><span class=\"ansigreen\">return</span> self<span class=\"ansiyellow\">.</span>func<span class=\"ansiyellow\">(</span><span class=\"ansiyellow\">*</span>self<span class=\"ansiyellow\">.</span>args<span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">**</span>self<span class=\"ansiyellow\">.</span>kwargs<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
206 "\n",
207 "<span class=\"ansigreen\">/home/fperez/ipython/ipython/docs/examples/lib/&lt;ipython-input-15-54795a097787&gt;</span> in <span class=\"ansicyan\">diefunc</span><span class=\"ansiblue\">(interval, *a, **kw)</span>\n",
208 "<span class=\"ansigreen\"> 14</span> <span class=\"ansigreen\">def</span> diefunc<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">2</span><span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">*</span>a<span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">**</span>kw<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
209 "<span class=\"ansigreen\"> 15</span> time<span class=\"ansiyellow\">.</span>sleep<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
210 "<span class=\"ansigreen\">---&gt; 16</span><span class=\"ansiyellow\"> </span><span class=\"ansigreen\">raise</span> Exception<span class=\"ansiyellow\">(</span><span class=\"ansiblue\">&quot;Dead job with interval %s&quot;</span> <span class=\"ansiyellow\">%</span> interval<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
211 "<span class=\"ansigreen\"> 17</span> <span class=\"ansiyellow\"></span>\n",
212 "<span class=\"ansigreen\"> 18</span> <span class=\"ansigreen\">def</span> printfunc<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">1</span><span class=\"ansiyellow\">,</span> reps<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">5</span><span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
213 "\n",
214 "<span class=\"ansired\">Exception</span>: Dead job with interval 1\n"
215 ]
192 ]
216 }
193 }
217 ],
194 ],
218 "prompt_number": 34
195 "prompt_number": 5
219 },
196 },
220 {
197 {
221 "cell_type": "markdown",
198 "cell_type": "markdown",
@@ -237,44 +214,44 b''
237 "output_type": "stream",
214 "output_type": "stream",
238 "stream": "stdout",
215 "stream": "stdout",
239 "text": [
216 "text": [
240 "Traceback for: &lt;BackgroundJob #4: &lt;function diefunc at 0x30df758&gt;&gt;\n",
217 "Traceback for: <BackgroundJob #4: <function diefunc at 0x7f2a1c996440>>\n",
241 "<span class=\"ansired\">---------------------------------------------------------------------------</span>\n",
218 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n",
242 "<span class=\"ansired\">Exception</span> Traceback (most recent call last)\n",
219 "\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n",
243 "<span class=\"ansigreen\">/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py</span> in <span class=\"ansicyan\">call</span><span class=\"ansiblue\">(self)</span>\n",
220 "\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",
244 "<span class=\"ansigreen\"> 462</span> <span class=\"ansiyellow\"></span>\n",
221 "\u001b[0;32m 489\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
245 "<span class=\"ansigreen\"> 463</span> <span class=\"ansigreen\">def</span> call<span class=\"ansiyellow\">(</span>self<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
222 "\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",
246 "<span class=\"ansigreen\">--&gt; 464</span><span class=\"ansiyellow\"> </span><span class=\"ansigreen\">return</span> self<span class=\"ansiyellow\">.</span>func<span class=\"ansiyellow\">(</span><span class=\"ansiyellow\">*</span>self<span class=\"ansiyellow\">.</span>args<span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">**</span>self<span class=\"ansiyellow\">.</span>kwargs<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
223 "\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",
224 "\u001b[0m\n",
225 "\u001b[1;32m<ipython-input-1-7391f8ae281b>\u001b[0m in \u001b[0;36mdiefunc\u001b[1;34m(interval, *a, **kw)\u001b[0m\n",
226 "\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",
227 "\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",
228 "\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",
229 "\u001b[0m\u001b[0;32m 17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
230 "\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",
247 "\n",
231 "\n",
248 "<span class=\"ansigreen\">/home/fperez/ipython/ipython/docs/examples/lib/&lt;ipython-input-15-54795a097787&gt;</span> in <span class=\"ansicyan\">diefunc</span><span class=\"ansiblue\">(interval, *a, **kw)</span>\n",
232 "\u001b[1;31mException\u001b[0m: Dead job with interval 1\n",
249 "<span class=\"ansigreen\"> 14</span> <span class=\"ansigreen\">def</span> diefunc<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">2</span><span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">*</span>a<span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">**</span>kw<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
250 "<span class=\"ansigreen\"> 15</span> time<span class=\"ansiyellow\">.</span>sleep<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
251 "<span class=\"ansigreen\">---&gt; 16</span><span class=\"ansiyellow\"> </span><span class=\"ansigreen\">raise</span> Exception<span class=\"ansiyellow\">(</span><span class=\"ansiblue\">&quot;Dead job with interval %s&quot;</span> <span class=\"ansiyellow\">%</span> interval<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
252 "<span class=\"ansigreen\"> 17</span> <span class=\"ansiyellow\"></span>\n",
253 "<span class=\"ansigreen\"> 18</span> <span class=\"ansigreen\">def</span> printfunc<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">1</span><span class=\"ansiyellow\">,</span> reps<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">5</span><span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
254 "\n",
233 "\n",
255 "<span class=\"ansired\">Exception</span>: Dead job with interval 1\n",
234 "Traceback for: <BackgroundJob #5: <function diefunc at 0x7f2a1c996440>>\n",
235 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n",
236 "\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n",
237 "\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",
238 "\u001b[0;32m 489\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
239 "\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",
240 "\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",
241 "\u001b[0m\n",
242 "\u001b[1;32m<ipython-input-1-7391f8ae281b>\u001b[0m in \u001b[0;36mdiefunc\u001b[1;34m(interval, *a, **kw)\u001b[0m\n",
243 "\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",
244 "\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",
245 "\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",
246 "\u001b[0m\u001b[0;32m 17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
247 "\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",
256 "\n",
248 "\n",
257 "Traceback for: &lt;BackgroundJob #5: &lt;function diefunc at 0x30df758&gt;&gt;\n",
249 "\u001b[1;31mException\u001b[0m: Dead job with interval 2\n",
258 "<span class=\"ansired\">---------------------------------------------------------------------------</span>\n",
259 "<span class=\"ansired\">Exception</span> Traceback (most recent call last)\n",
260 "<span class=\"ansigreen\">/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py</span> in <span class=\"ansicyan\">call</span><span class=\"ansiblue\">(self)</span>\n",
261 "<span class=\"ansigreen\"> 462</span> <span class=\"ansiyellow\"></span>\n",
262 "<span class=\"ansigreen\"> 463</span> <span class=\"ansigreen\">def</span> call<span class=\"ansiyellow\">(</span>self<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
263 "<span class=\"ansigreen\">--&gt; 464</span><span class=\"ansiyellow\"> </span><span class=\"ansigreen\">return</span> self<span class=\"ansiyellow\">.</span>func<span class=\"ansiyellow\">(</span><span class=\"ansiyellow\">*</span>self<span class=\"ansiyellow\">.</span>args<span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">**</span>self<span class=\"ansiyellow\">.</span>kwargs<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
264 "\n",
265 "<span class=\"ansigreen\">/home/fperez/ipython/ipython/docs/examples/lib/&lt;ipython-input-15-54795a097787&gt;</span> in <span class=\"ansicyan\">diefunc</span><span class=\"ansiblue\">(interval, *a, **kw)</span>\n",
266 "<span class=\"ansigreen\"> 14</span> <span class=\"ansigreen\">def</span> diefunc<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">2</span><span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">*</span>a<span class=\"ansiyellow\">,</span> <span class=\"ansiyellow\">**</span>kw<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
267 "<span class=\"ansigreen\"> 15</span> time<span class=\"ansiyellow\">.</span>sleep<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
268 "<span class=\"ansigreen\">---&gt; 16</span><span class=\"ansiyellow\"> </span><span class=\"ansigreen\">raise</span> Exception<span class=\"ansiyellow\">(</span><span class=\"ansiblue\">&quot;Dead job with interval %s&quot;</span> <span class=\"ansiyellow\">%</span> interval<span class=\"ansiyellow\">)</span><span class=\"ansiyellow\"></span>\n",
269 "<span class=\"ansigreen\"> 17</span> <span class=\"ansiyellow\"></span>\n",
270 "<span class=\"ansigreen\"> 18</span> <span class=\"ansigreen\">def</span> printfunc<span class=\"ansiyellow\">(</span>interval<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">1</span><span class=\"ansiyellow\">,</span> reps<span class=\"ansiyellow\">=</span><span class=\"ansicyan\">5</span><span class=\"ansiyellow\">)</span><span class=\"ansiyellow\">:</span><span class=\"ansiyellow\"></span>\n",
271 "\n",
272 "<span class=\"ansired\">Exception</span>: Dead job with interval 2\n",
273 "\n"
250 "\n"
274 ]
251 ]
275 }
252 }
276 ],
253 ],
277 "prompt_number": 33
254 "prompt_number": 6
278 },
255 },
279 {
256 {
280 "cell_type": "markdown",
257 "cell_type": "markdown",
@@ -296,11 +273,12 b''
296 "output_type": "stream",
273 "output_type": "stream",
297 "stream": "stdout",
274 "stream": "stdout",
298 "text": [
275 "text": [
299 "No jobs to flush.\n"
276 "Flushing 3 Completed jobs.\n",
277 "Flushing 2 Dead jobs.\n"
300 ]
278 ]
301 }
279 }
302 ],
280 ],
303 "prompt_number": 25
281 "prompt_number": 7
304 },
282 },
305 {
283 {
306 "cell_type": "markdown",
284 "cell_type": "markdown",
@@ -318,7 +296,7 b''
318 "language": "python",
296 "language": "python",
319 "metadata": {},
297 "metadata": {},
320 "outputs": [],
298 "outputs": [],
321 "prompt_number": 27
299 "prompt_number": 8
322 },
300 },
323 {
301 {
324 "cell_type": "markdown",
302 "cell_type": "markdown",
@@ -332,10 +310,10 b''
332 "collapsed": false,
310 "collapsed": false,
333 "input": [
311 "input": [
334 "j = jobs.new(sleepfunc, 2)\n",
312 "j = jobs.new(sleepfunc, 2)\n",
335 "print \"Will wait for j now...\"\n",
313 "print(\"Will wait for j now...\")\n",
336 "sys.stdout.flush()\n",
314 "sys.stdout.flush()\n",
337 "j.join()\n",
315 "j.join()\n",
338 "print \"Result from j:\"\n",
316 "print(\"Result from j:\")\n",
339 "j.result"
317 "j.result"
340 ],
318 ],
341 "language": "python",
319 "language": "python",
@@ -345,7 +323,7 b''
345 "output_type": "stream",
323 "output_type": "stream",
346 "stream": "stdout",
324 "stream": "stdout",
347 "text": [
325 "text": [
348 "Starting job # 7 in a separate thread.\n",
326 "Starting job # 0 in a separate thread.\n",
349 "Will wait for j now...\n"
327 "Will wait for j now...\n"
350 ]
328 ]
351 },
329 },
@@ -357,14 +335,15 b''
357 ]
335 ]
358 },
336 },
359 {
337 {
338 "metadata": {},
360 "output_type": "pyout",
339 "output_type": "pyout",
361 "prompt_number": 46,
340 "prompt_number": 9,
362 "text": [
341 "text": [
363 "{&apos;args&apos;: (), &apos;interval&apos;: 2, &apos;kwargs&apos;: {}}"
342 "{'kwargs': {}, 'args': (), 'interval': 2}"
364 ]
343 ]
365 }
344 }
366 ],
345 ],
367 "prompt_number": 46
346 "prompt_number": 9
368 },
347 },
369 {
348 {
370 "cell_type": "code",
349 "cell_type": "code",
@@ -10,7 +10,6 b' In [6]: %run gui-qt.py'
10 Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/
10 Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/
11 """
11 """
12
12
13 import sys
14 from PyQt4 import QtGui, QtCore
13 from PyQt4 import QtGui, QtCore
15
14
16 class SimpleWindow(QtGui.QWidget):
15 class SimpleWindow(QtGui.QWidget):
@@ -8,7 +8,10 b' In [5]: %gui tk'
8 In [6]: %run gui-tk.py
8 In [6]: %run gui-tk.py
9 """
9 """
10
10
11 from Tkinter import *
11 try:
12 from tkinter import * # Python 3
13 except ImportError:
14 from Tkinter import * # Python 2
12
15
13 class MyApp:
16 class MyApp:
14
17
@@ -2,7 +2,6 b''
2 # Imports
2 # Imports
3 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
4
4
5 import subprocess
6 import sys
5 import sys
7
6
8 from IPython.lib.kernel import connect_qtconsole
7 from IPython.lib.kernel import connect_qtconsole
@@ -42,7 +41,7 b' class InternalIPKernel(object):'
42
41
43 def print_namespace(self, evt=None):
42 def print_namespace(self, evt=None):
44 print("\n***Variables in User namespace***")
43 print("\n***Variables in User namespace***")
45 for k, v in self.namespace.iteritems():
44 for k, v in self.namespace.items():
46 if k not in self._init_keys and not k.startswith('_'):
45 if k not in self._init_keys and not k.startswith('_'):
47 print('%s -> %r' % (k, v))
46 print('%s -> %r' % (k, v))
48 sys.stdout.flush()
47 sys.stdout.flush()
@@ -153,9 +153,8 b''
153 "collapsed": false,
153 "collapsed": false,
154 "input": [
154 "input": [
155 "# Python 3 compat\n",
155 "# Python 3 compat\n",
156 "try:\n",
156 "import sys\n",
157 " raw_input\n",
157 "if sys.version_info[0] >= 3:\n",
158 "except NameError:\n",
159 " raw_input = input"
158 " raw_input = input"
160 ],
159 ],
161 "language": "python",
160 "language": "python",
@@ -157,7 +157,7 b''
157 " # transform the input to executable Python\n",
157 " # transform the input to executable Python\n",
158 " code = self.shell.input_transformer_manager.transform_cell(cell.input)\n",
158 " code = self.shell.input_transformer_manager.transform_cell(cell.input)\n",
159 " # run the code in themodule\n",
159 " # run the code in themodule\n",
160 " exec code in mod.__dict__\n",
160 " exec(code, mod.__dict__)\n",
161 " finally:\n",
161 " finally:\n",
162 " self.shell.user_ns = save_user_ns\n",
162 " self.shell.user_ns = save_user_ns\n",
163 " return mod\n"
163 " return mod\n"
@@ -989,24 +989,6 b''
989 "cell_type": "markdown",
989 "cell_type": "markdown",
990 "metadata": {},
990 "metadata": {},
991 "source": [
991 "source": [
992 "By default, `DataFrames` will be represented as text; to enable HTML representations we need to set a print option:"
993 ]
994 },
995 {
996 "cell_type": "code",
997 "collapsed": false,
998 "input": [
999 "pandas.core.format.set_printoptions(notebook_repr_html=True)"
1000 ],
1001 "language": "python",
1002 "metadata": {},
1003 "outputs": [],
1004 "prompt_number": 9
1005 },
1006 {
1007 "cell_type": "markdown",
1008 "metadata": {},
1009 "source": [
1010 "Here is a small amount of stock data for APPL:"
992 "Here is a small amount of stock data for APPL:"
1011 ]
993 ]
1012 },
994 },
@@ -67,7 +67,7 b''
67 "cell_type": "code",
67 "cell_type": "code",
68 "collapsed": false,
68 "collapsed": false,
69 "input": [
69 "input": [
70 "%px print a"
70 "%px print(a)"
71 ],
71 ],
72 "language": "python",
72 "language": "python",
73 "metadata": {},
73 "metadata": {},
@@ -98,7 +98,8 b''
98 "cell_type": "code",
98 "cell_type": "code",
99 "collapsed": false,
99 "collapsed": false,
100 "input": [
100 "input": [
101 "%px print >> sys.stderr, \"ERROR\""
101 "%px from __future__ import print_function\n",
102 "%px print(\"ERROR\", file=sys.stderr)"
102 ],
103 ],
103 "language": "python",
104 "language": "python",
104 "metadata": {},
105 "metadata": {},
@@ -208,7 +209,7 b''
208 "%%px --noblock\n",
209 "%%px --noblock\n",
209 "x = np.linspace(0,np.pi,1000)\n",
210 "x = np.linspace(0,np.pi,1000)\n",
210 "for n in range(id,12, stride):\n",
211 "for n in range(id,12, stride):\n",
211 " print n\n",
212 " print(n)\n",
212 " plt.plot(x,np.sin(n*x))\n",
213 " plt.plot(x,np.sin(n*x))\n",
213 "plt.title(\"Plot %i\" % id)"
214 "plt.title(\"Plot %i\" % id)"
214 ],
215 ],
@@ -248,7 +249,7 b''
248 "%%px --group-outputs=engine\n",
249 "%%px --group-outputs=engine\n",
249 "x = np.linspace(0,np.pi,1000)\n",
250 "x = np.linspace(0,np.pi,1000)\n",
250 "for n in range(id+1,12, stride):\n",
251 "for n in range(id+1,12, stride):\n",
251 " print n\n",
252 " print(n)\n",
252 " plt.figure()\n",
253 " plt.figure()\n",
253 " plt.plot(x,np.sin(n*x))\n",
254 " plt.plot(x,np.sin(n*x))\n",
254 " plt.title(\"Plot %i\" % n)"
255 " plt.title(\"Plot %i\" % n)"
@@ -296,6 +297,8 b''
296 "cell_type": "code",
297 "cell_type": "code",
297 "collapsed": false,
298 "collapsed": false,
298 "input": [
299 "input": [
300 "from __future__ import print_function\n",
301 "\n",
299 "def generate_output():\n",
302 "def generate_output():\n",
300 " \"\"\"function for testing output\n",
303 " \"\"\"function for testing output\n",
301 " \n",
304 " \n",
@@ -305,13 +308,13 b''
305 " import sys,os\n",
308 " import sys,os\n",
306 " from IPython.display import display, HTML, Math\n",
309 " from IPython.display import display, HTML, Math\n",
307 " \n",
310 " \n",
308 " print \"stdout\"\n",
311 " print(\"stdout\")\n",
309 " print >> sys.stderr, \"stderr\"\n",
312 " print(\"stderr\", file=sys.stderr)\n",
310 " \n",
313 " \n",
311 " display(HTML(\"<b>HTML</b>\"))\n",
314 " display(HTML(\"<b>HTML</b>\"))\n",
312 " \n",
315 " \n",
313 " print \"stdout2\"\n",
316 " print(\"stdout2\")\n",
314 " print >> sys.stderr, \"stderr2\"\n",
317 " print(\"stderr2\", file=sys.stderr)\n",
315 " \n",
318 " \n",
316 " display(Math(r\"\\alpha=\\beta\"))\n",
319 " display(Math(r\"\\alpha=\\beta\"))\n",
317 " \n",
320 " \n",
@@ -461,7 +464,7 b''
461 "cell_type": "markdown",
464 "cell_type": "markdown",
462 "metadata": {},
465 "metadata": {},
463 "source": [
466 "source": [
464 "As of IPython 0.14, you can instruct `%%px` to also execute the cell locally.\n",
467 "As of IPython 1.0, you can instruct `%%px` to also execute the cell locally.\n",
465 "This is useful for interactive definitions,\n",
468 "This is useful for interactive definitions,\n",
466 "or if you want to load a data source everywhere,\n",
469 "or if you want to load a data source everywhere,\n",
467 "not just on the engines."
470 "not just on the engines."
@@ -474,7 +477,7 b''
474 "%%px --local\n",
477 "%%px --local\n",
475 "import os\n",
478 "import os\n",
476 "thispid = os.getpid()\n",
479 "thispid = os.getpid()\n",
477 "print thispid"
480 "print(thispid)"
478 ],
481 ],
479 "language": "python",
482 "language": "python",
480 "metadata": {},
483 "metadata": {},
@@ -1,6 +1,6 b''
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "name": "helloworld"
3 "name": ""
4 },
4 },
5 "nbformat": 3,
5 "nbformat": 3,
6 "nbformat_minor": 0,
6 "nbformat_minor": 0,
@@ -20,6 +20,7 b''
20 "cell_type": "code",
20 "cell_type": "code",
21 "collapsed": true,
21 "collapsed": true,
22 "input": [
22 "input": [
23 "from __future__ import print_function\n",
23 "from IPython.parallel import Client"
24 "from IPython.parallel import Client"
24 ],
25 ],
25 "language": "python",
26 "language": "python",
@@ -69,8 +70,8 b''
69 "cell_type": "code",
70 "cell_type": "code",
70 "collapsed": false,
71 "collapsed": false,
71 "input": [
72 "input": [
72 "print \"Submitted tasks:\", hello.msg_ids + world.msg_ids\n",
73 "print(\"Submitted tasks:\", hello.msg_ids + world.msg_ids)\n",
73 "print hello.get(), world.get()"
74 "print(hello.get(), world.get())"
74 ],
75 ],
75 "language": "python",
76 "language": "python",
76 "metadata": {},
77 "metadata": {},
@@ -18,6 +18,7 b''
18 "cell_type": "code",
18 "cell_type": "code",
19 "collapsed": true,
19 "collapsed": true,
20 "input": [
20 "input": [
21 "from __future__ import print_function\n",
21 "from IPython.parallel import Client"
22 "from IPython.parallel import Client"
22 ],
23 ],
23 "language": "python",
24 "language": "python",
@@ -110,7 +111,7 b''
110 "cell_type": "code",
111 "cell_type": "code",
111 "collapsed": false,
112 "collapsed": false,
112 "input": [
113 "input": [
113 "print \"a, b, c: \", ar.get()"
114 "print(\"a, b, c: \", ar.get())"
114 ],
115 ],
115 "language": "python",
116 "language": "python",
116 "metadata": {},
117 "metadata": {},
@@ -1,6 +1,6 b''
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "name": "taskmap"
3 "name": ""
4 },
4 },
5 "nbformat": 3,
5 "nbformat": 3,
6 "nbformat_minor": 0,
6 "nbformat_minor": 0,
@@ -18,6 +18,7 b''
18 "cell_type": "code",
18 "cell_type": "code",
19 "collapsed": true,
19 "collapsed": true,
20 "input": [
20 "input": [
21 "from __future__ import print_function\n",
21 "from IPython.parallel import Client"
22 "from IPython.parallel import Client"
22 ],
23 ],
23 "language": "python",
24 "language": "python",
@@ -42,7 +43,7 b''
42 "collapsed": false,
43 "collapsed": false,
43 "input": [
44 "input": [
44 "result = v.map(lambda x: 2*x, range(10))\n",
45 "result = v.map(lambda x: 2*x, range(10))\n",
45 "print \"Simple, default map: \", list(result)"
46 "print(\"Simple, default map: \", list(result))"
46 ],
47 ],
47 "language": "python",
48 "language": "python",
48 "metadata": {},
49 "metadata": {},
@@ -69,9 +70,9 b''
69 "collapsed": false,
70 "collapsed": false,
70 "input": [
71 "input": [
71 "ar = v.map_async(lambda x: 2*x, range(10))\n",
72 "ar = v.map_async(lambda x: 2*x, range(10))\n",
72 "print \"Submitted tasks, got ids: \", ar.msg_ids\n",
73 "print(\"Submitted tasks, got ids: \", ar.msg_ids)\n",
73 "result = ar.get()\n",
74 "result = ar.get()\n",
74 "print \"Using a mapper: \", result"
75 "print(\"Using a mapper: \", result)"
75 ],
76 ],
76 "language": "python",
77 "language": "python",
77 "metadata": {},
78 "metadata": {},
@@ -95,7 +96,7 b''
95 "def f(x): return 2*x\n",
96 "def f(x): return 2*x\n",
96 "\n",
97 "\n",
97 "result = f.map(range(10))\n",
98 "result = f.map(range(10))\n",
98 "print \"Using a parallel function: \", result"
99 "print(\"Using a parallel function: \", result)"
99 ],
100 ],
100 "language": "python",
101 "language": "python",
101 "metadata": {},
102 "metadata": {},
@@ -29,7 +29,7 b''
29 "cell_type": "code",
29 "cell_type": "code",
30 "collapsed": false,
30 "collapsed": false,
31 "input": [
31 "input": [
32 "print 'hi'"
32 "print('hi')"
33 ],
33 ],
34 "language": "python",
34 "language": "python",
35 "metadata": {},
35 "metadata": {},
@@ -180,7 +180,7 b''
180 "cell_type": "code",
180 "cell_type": "code",
181 "collapsed": false,
181 "collapsed": false,
182 "input": [
182 "input": [
183 "# press tab after parentheses\n",
183 "# press shift-tab after parentheses\n",
184 "int("
184 "int("
185 ],
185 ],
186 "language": "python",
186 "language": "python",
@@ -199,7 +199,7 b''
199 "cell_type": "code",
199 "cell_type": "code",
200 "collapsed": false,
200 "collapsed": false,
201 "input": [
201 "input": [
202 "# pres tab after f\n",
202 "# press tab after f\n",
203 "f"
203 "f"
204 ],
204 ],
205 "language": "python",
205 "language": "python",
@@ -218,7 +218,7 b''
218 "cell_type": "code",
218 "cell_type": "code",
219 "collapsed": false,
219 "collapsed": false,
220 "input": [
220 "input": [
221 "import sys\n",
221 "import sys, time\n",
222 "from IPython.display import clear_output"
222 "from IPython.display import clear_output"
223 ],
223 ],
224 "language": "python",
224 "language": "python",
@@ -232,7 +232,7 b''
232 "for i in range(10):\n",
232 "for i in range(10):\n",
233 " clear_output()\n",
233 " clear_output()\n",
234 " time.sleep(0.25)\n",
234 " time.sleep(0.25)\n",
235 " print i\n",
235 " print(i)\n",
236 " sys.stdout.flush()\n",
236 " sys.stdout.flush()\n",
237 " time.sleep(0.25)\n"
237 " time.sleep(0.25)\n"
238 ],
238 ],
@@ -247,7 +247,7 b''
247 "for i in range(10):\n",
247 "for i in range(10):\n",
248 " clear_output(wait=True)\n",
248 " clear_output(wait=True)\n",
249 " time.sleep(0.25)\n",
249 " time.sleep(0.25)\n",
250 " print i\n",
250 " print(i)\n",
251 " sys.stdout.flush()\n"
251 " sys.stdout.flush()\n"
252 ],
252 ],
253 "language": "python",
253 "language": "python",
General Comments 0
You need to be logged in to leave comments. Login now