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