##// END OF EJS Templates
update raw_input in example notebook
MinRK -
Show More
@@ -1,271 +1,322 b''
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "name": "Frontend-Kernel Model"
3 "name": ""
4 },
4 },
5 "nbformat": 3,
5 "nbformat": 3,
6 "nbformat_minor": 0,
6 "nbformat_minor": 0,
7 "worksheets": [
7 "worksheets": [
8 {
8 {
9 "cells": [
9 "cells": [
10 {
10 {
11 "cell_type": "heading",
11 "cell_type": "heading",
12 "level": 1,
12 "level": 1,
13 "metadata": {},
13 "metadata": {},
14 "source": [
14 "source": [
15 "The Frontend/Kernel Model"
15 "The Frontend/Kernel Model"
16 ]
16 ]
17 },
17 },
18 {
18 {
19 "cell_type": "markdown",
19 "cell_type": "markdown",
20 "metadata": {},
20 "metadata": {},
21 "source": [
21 "source": [
22 "The traditional IPython (`ipython`) consists of a single process that combines a terminal based UI with the process that runs the users code.\n",
22 "The traditional IPython (`ipython`) consists of a single process that combines a terminal based UI with the process that runs the users code.\n",
23 "\n",
23 "\n",
24 "While this traditional application still exists, the modern IPython consists of two processes:\n",
24 "While this traditional application still exists, the modern IPython consists of two processes:\n",
25 "\n",
25 "\n",
26 "* Kernel: this is the process that runs the users code.\n",
26 "* Kernel: this is the process that runs the users code.\n",
27 "* Frontend: this is the process that provides the user interface where the user types code and sees results.\n",
27 "* Frontend: this is the process that provides the user interface where the user types code and sees results.\n",
28 "\n",
28 "\n",
29 "IPython currently has 3 frontends:\n",
29 "IPython currently has 3 frontends:\n",
30 "\n",
30 "\n",
31 "* Terminal Console (`ipython console`)\n",
31 "* Terminal Console (`ipython console`)\n",
32 "* Qt Console (`ipython qtconsole`)\n",
32 "* Qt Console (`ipython qtconsole`)\n",
33 "* Notebook (`ipython notebook`)\n",
33 "* Notebook (`ipython notebook`)\n",
34 "\n",
34 "\n",
35 "The Kernel and Frontend communicate over a ZeroMQ/JSON based messaging protocol, which allows multiple Frontends (even of different types) to communicate with a single Kernel. This opens the door for all sorts of interesting things, such as connecting a Console or Qt Console to a Notebook's Kernel. For example, you may want to connect a Qt console to your Notebook's Kernel and use it as a help\n",
35 "The Kernel and Frontend communicate over a ZeroMQ/JSON based messaging protocol, which allows multiple Frontends (even of different types) to communicate with a single Kernel. This opens the door for all sorts of interesting things, such as connecting a Console or Qt Console to a Notebook's Kernel. For example, you may want to connect a Qt console to your Notebook's Kernel and use it as a help\n",
36 "browser, calling `??` on objects in the Qt console (whose pager is more flexible than the\n",
36 "browser, calling `??` on objects in the Qt console (whose pager is more flexible than the\n",
37 "one in the notebook). \n",
37 "one in the notebook). \n",
38 "\n",
38 "\n",
39 "This Notebook describes how you would connect another Frontend to a Kernel that is associated with a Notebook."
39 "This Notebook describes how you would connect another Frontend to a Kernel that is associated with a Notebook."
40 ]
40 ]
41 },
41 },
42 {
42 {
43 "cell_type": "heading",
43 "cell_type": "heading",
44 "level": 2,
44 "level": 2,
45 "metadata": {},
45 "metadata": {},
46 "source": [
46 "source": [
47 "Manual connection"
47 "Manual connection"
48 ]
48 ]
49 },
49 },
50 {
50 {
51 "cell_type": "markdown",
51 "cell_type": "markdown",
52 "metadata": {},
52 "metadata": {},
53 "source": [
53 "source": [
54 "To connect another Frontend to a Kernel manually, you first need to find out the connection information for the Kernel using the `%connect_info` magic:"
54 "To connect another Frontend to a Kernel manually, you first need to find out the connection information for the Kernel using the `%connect_info` magic:"
55 ]
55 ]
56 },
56 },
57 {
57 {
58 "cell_type": "code",
58 "cell_type": "code",
59 "collapsed": false,
59 "collapsed": false,
60 "input": [
60 "input": [
61 "%connect_info"
61 "%connect_info"
62 ],
62 ],
63 "language": "python",
63 "language": "python",
64 "metadata": {},
64 "metadata": {},
65 "outputs": [
65 "outputs": [
66 {
66 {
67 "output_type": "stream",
67 "output_type": "stream",
68 "stream": "stdout",
68 "stream": "stdout",
69 "text": [
69 "text": [
70 "{\n",
70 "{\n",
71 " \"stdin_port\": 52858, \n",
71 " \"stdin_port\": 52858, \n",
72 " \"ip\": \"127.0.0.1\", \n",
72 " \"ip\": \"127.0.0.1\", \n",
73 " \"hb_port\": 52859, \n",
73 " \"hb_port\": 52859, \n",
74 " \"key\": \"7efd45ca-d8a2-41b0-9cea-d9116d0fb883\", \n",
74 " \"key\": \"7efd45ca-d8a2-41b0-9cea-d9116d0fb883\", \n",
75 " \"shell_port\": 52856, \n",
75 " \"shell_port\": 52856, \n",
76 " \"iopub_port\": 52857\n",
76 " \"iopub_port\": 52857\n",
77 "}\n",
77 "}\n",
78 "\n",
78 "\n",
79 "Paste the above JSON into a file, and connect with:\n",
79 "Paste the above JSON into a file, and connect with:\n",
80 " $> ipython <app> --existing <file>\n",
80 " $> ipython <app> --existing <file>\n",
81 "or, if you are local, you can connect with just:\n",
81 "or, if you are local, you can connect with just:\n",
82 " $> ipython <app> --existing kernel-b3bac7c1-8b2c-4536-8082-8d1df24f99ac.json \n",
82 " $> ipython <app> --existing kernel-b3bac7c1-8b2c-4536-8082-8d1df24f99ac.json \n",
83 "or even just:\n",
83 "or even just:\n",
84 " $> ipython <app> --existing \n",
84 " $> ipython <app> --existing \n",
85 "if this is the most recent IPython session you have started.\n"
85 "if this is the most recent IPython session you have started.\n"
86 ]
86 ]
87 }
87 }
88 ],
88 ],
89 "prompt_number": 6
89 "prompt_number": 6
90 },
90 },
91 {
91 {
92 "cell_type": "markdown",
92 "cell_type": "markdown",
93 "metadata": {},
93 "metadata": {},
94 "source": [
94 "source": [
95 "You can see that this magic displays everything you need to connect to this Notebook's Kernel."
95 "You can see that this magic displays everything you need to connect to this Notebook's Kernel."
96 ]
96 ]
97 },
97 },
98 {
98 {
99 "cell_type": "heading",
99 "cell_type": "heading",
100 "level": 2,
100 "level": 2,
101 "metadata": {},
101 "metadata": {},
102 "source": [
102 "source": [
103 "Automatic connection using a new Qt Console"
103 "Automatic connection using a new Qt Console"
104 ]
104 ]
105 },
105 },
106 {
106 {
107 "cell_type": "markdown",
107 "cell_type": "markdown",
108 "metadata": {},
108 "metadata": {},
109 "source": [
109 "source": [
110 "You can also start a new Qt Console connected to your current Kernel by using the `%qtconsole` magic. This will detect the necessary connection\n",
110 "You can also start a new Qt Console connected to your current Kernel by using the `%qtconsole` magic. This will detect the necessary connection\n",
111 "information and start the Qt Console for you automatically."
111 "information and start the Qt Console for you automatically."
112 ]
112 ]
113 },
113 },
114 {
114 {
115 "cell_type": "code",
115 "cell_type": "code",
116 "collapsed": false,
116 "collapsed": false,
117 "input": [
117 "input": [
118 "a = 10"
118 "a = 10"
119 ],
119 ],
120 "language": "python",
120 "language": "python",
121 "metadata": {},
121 "metadata": {},
122 "outputs": [],
122 "outputs": [],
123 "prompt_number": 1
123 "prompt_number": 1
124 },
124 },
125 {
125 {
126 "cell_type": "code",
126 "cell_type": "code",
127 "collapsed": false,
127 "collapsed": false,
128 "input": [
128 "input": [
129 "%qtconsole"
129 "%qtconsole"
130 ],
130 ],
131 "language": "python",
131 "language": "python",
132 "metadata": {},
132 "metadata": {},
133 "outputs": [],
133 "outputs": [],
134 "prompt_number": 2
134 "prompt_number": 2
135 },
135 },
136 {
136 {
137 "cell_type": "heading",
137 "cell_type": "heading",
138 "level": 2,
138 "level": 2,
139 "metadata": {},
139 "metadata": {},
140 "source": [
140 "source": [
141 "The kernel's `raw_input` and `%debug`"
141 "The kernel's `raw_input` and `%debug`"
142 ]
142 ]
143 },
143 },
144 {
144 {
145 "cell_type": "markdown",
145 "cell_type": "markdown",
146 "metadata": {},
146 "metadata": {},
147 "source": [
147 "source": [
148 "The Notebook has added support for `raw_input` and `%debug`, as of 1.0."
148 "The Notebook has added support for `raw_input` and `%debug`, as of 1.0."
149 ]
149 ]
150 },
150 },
151 {
151 {
152 "cell_type": "code",
152 "cell_type": "code",
153 "collapsed": false,
153 "collapsed": false,
154 "input": [
154 "input": [
155 "# Python 3 compat\n",
156 "try:\n",
157 " raw_input\n",
158 "except NameError:\n",
159 " raw_input = input"
160 ],
161 "language": "python",
162 "metadata": {},
163 "outputs": [],
164 "prompt_number": 1
165 },
166 {
167 "cell_type": "code",
168 "collapsed": false,
169 "input": [
155 "name = raw_input(\"What is your name? \")\n",
170 "name = raw_input(\"What is your name? \")\n",
156 "name"
171 "name"
157 ],
172 ],
158 "language": "python",
173 "language": "python",
159 "metadata": {},
174 "metadata": {},
160 "outputs": [
175 "outputs": [
161 {
176 {
162 "name": "stdout",
177 "name": "stdout",
163 "output_type": "stream",
178 "output_type": "stream",
164 "stream": "stdout",
179 "stream": "stdout",
165 "text": [
180 "text": [
166 "What is your name? Sir Robin\n"
181 "What is your name? Sir Robin\n"
167 ]
182 ]
168 },
183 },
169 {
184 {
170 "metadata": {},
185 "metadata": {},
171 "output_type": "pyout",
186 "output_type": "pyout",
172 "prompt_number": 1,
187 "prompt_number": 2,
173 "text": [
188 "text": [
174 "u'Sir Robin'"
189 "'Sir Robin'"
175 ]
190 ]
176 }
191 }
177 ],
192 ],
178 "prompt_number": 1
193 "prompt_number": 2
194 },
195 {
196 "cell_type": "markdown",
197 "metadata": {},
198 "source": [
199 "**Python 2-only**: the eval input works as well (`input` is just `eval(raw_input(prompt))`)"
200 ]
201 },
202 {
203 "cell_type": "code",
204 "collapsed": false,
205 "input": [
206 "fingers = input(\"How many fingers? \")\n",
207 "fingers, type(fingers)"
208 ],
209 "language": "python",
210 "metadata": {},
211 "outputs": [
212 {
213 "name": "stdout",
214 "output_type": "stream",
215 "stream": "stdout",
216 "text": [
217 "How many fingers? 4\n"
218 ]
219 },
220 {
221 "metadata": {},
222 "output_type": "pyout",
223 "prompt_number": 3,
224 "text": [
225 "(4, int)"
226 ]
227 }
228 ],
229 "prompt_number": 3
179 },
230 },
180 {
231 {
181 "cell_type": "code",
232 "cell_type": "code",
182 "collapsed": false,
233 "collapsed": false,
183 "input": [
234 "input": [
184 "def div(x, y):\n",
235 "def div(x, y):\n",
185 " return x/y\n",
236 " return x/y\n",
186 "\n",
237 "\n",
187 "div(1,0)"
238 "div(1,0)"
188 ],
239 ],
189 "language": "python",
240 "language": "python",
190 "metadata": {},
241 "metadata": {},
191 "outputs": [
242 "outputs": [
192 {
243 {
193 "ename": "ZeroDivisionError",
244 "ename": "ZeroDivisionError",
194 "evalue": "integer division or modulo by zero",
245 "evalue": "integer division or modulo by zero",
195 "output_type": "pyerr",
246 "output_type": "pyerr",
196 "traceback": [
247 "traceback": [
197 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
248 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
198 "\u001b[1;32m<ipython-input-2-a5097cc0c0c5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
249 "\u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
199 "\u001b[1;32m<ipython-input-2-a5097cc0c0c5>\u001b[0m in \u001b[0;36mdiv\u001b[1;34m(x, y)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
250 "\u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m in \u001b[0;36mdiv\u001b[1;34m(x, y)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
200 "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero"
251 "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero"
201 ]
252 ]
202 }
253 }
203 ],
254 ],
204 "prompt_number": 2
255 "prompt_number": 4
205 },
256 },
206 {
257 {
207 "cell_type": "code",
258 "cell_type": "code",
208 "collapsed": false,
259 "collapsed": false,
209 "input": [
260 "input": [
210 "%debug"
261 "%debug"
211 ],
262 ],
212 "language": "python",
263 "language": "python",
213 "metadata": {},
264 "metadata": {},
214 "outputs": [
265 "outputs": [
215 {
266 {
216 "output_type": "stream",
267 "output_type": "stream",
217 "stream": "stdout",
268 "stream": "stdout",
218 "text": [
269 "text": [
219 "> \u001b[1;32m<ipython-input-2-a5097cc0c0c5>\u001b[0m(2)\u001b[0;36mdiv\u001b[1;34m()\u001b[0m\n",
270 "> \u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m(2)\u001b[0;36mdiv\u001b[1;34m()\u001b[0m\n",
220 "\u001b[1;32m 1 \u001b[1;33m\u001b[1;32mdef\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
271 "\u001b[1;32m 1 \u001b[1;33m\u001b[1;32mdef\u001b[0m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
221 "\u001b[0m\u001b[1;32m----> 2 \u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
272 "\u001b[0m\u001b[1;32m----> 2 \u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
222 "\u001b[0m\u001b[1;32m 3 \u001b[1;33m\u001b[1;33m\u001b[0m\u001b[0m\n",
273 "\u001b[0m\u001b[1;32m 3 \u001b[1;33m\u001b[1;33m\u001b[0m\u001b[0m\n",
223 "\u001b[0m\n"
274 "\u001b[0m\n"
224 ]
275 ]
225 },
276 },
226 {
277 {
227 "name": "stdout",
278 "name": "stdout",
228 "output_type": "stream",
279 "output_type": "stream",
229 "stream": "stdout",
280 "stream": "stdout",
230 "text": [
281 "text": [
231 "ipdb> x\n"
282 "ipdb> x\n"
232 ]
283 ]
233 },
284 },
234 {
285 {
235 "output_type": "stream",
286 "output_type": "stream",
236 "stream": "stdout",
287 "stream": "stdout",
237 "text": [
288 "text": [
238 "1\n"
289 "1\n"
239 ]
290 ]
240 },
291 },
241 {
292 {
242 "name": "stdout",
293 "name": "stdout",
243 "output_type": "stream",
294 "output_type": "stream",
244 "stream": "stdout",
295 "stream": "stdout",
245 "text": [
296 "text": [
246 "ipdb> y\n"
297 "ipdb> y\n"
247 ]
298 ]
248 },
299 },
249 {
300 {
250 "output_type": "stream",
301 "output_type": "stream",
251 "stream": "stdout",
302 "stream": "stdout",
252 "text": [
303 "text": [
253 "0\n"
304 "0\n"
254 ]
305 ]
255 },
306 },
256 {
307 {
257 "name": "stdout",
308 "name": "stdout",
258 "output_type": "stream",
309 "output_type": "stream",
259 "stream": "stdout",
310 "stream": "stdout",
260 "text": [
311 "text": [
261 "ipdb> exit\n"
312 "ipdb> exit\n"
262 ]
313 ]
263 }
314 }
264 ],
315 ],
265 "prompt_number": 3
316 "prompt_number": 5
266 }
317 }
267 ],
318 ],
268 "metadata": {}
319 "metadata": {}
269 }
320 }
270 ]
321 ]
271 } No newline at end of file
322 }
General Comments 0
You need to be logged in to leave comments. Login now