##// END OF EJS Templates
More changes to example notebooks for Python 3 compatibility
Thomas Kluyver -
Show More
@@ -52,7 +52,7
52 52 "cell_type": "code",
53 53 "collapsed": false,
54 54 "input": [
55 "print a"
55 "print(a)"
56 56 ],
57 57 "language": "python",
58 58 "metadata": {},
@@ -120,7 +120,7
120 120 "import sys\n",
121 121 "from ctypes import CDLL\n",
122 122 "# This will crash a Linux or Mac system; equivalent calls can be made on Windows\n",
123 "dll = 'dylib' if sys.platform == 'darwin' else '.so.6'\n",
123 "dll = 'dylib' if sys.platform == 'darwin' else 'so.6'\n",
124 124 "libc = CDLL(\"libc.%s\" % dll) \n",
125 125 "libc.time(-1) # BOOM!!"
126 126 ],
@@ -324,7 +324,7
324 324 "input": [
325 325 ">>> the_world_is_flat = 1\n",
326 326 ">>> if the_world_is_flat:\n",
327 "... print \"Be careful not to fall off!\""
327 "... print(\"Be careful not to fall off!\")"
328 328 ],
329 329 "language": "python",
330 330 "metadata": {},
@@ -47,7 +47,8
47 47 "cell_type": "code",
48 48 "collapsed": false,
49 49 "input": [
50 "import numpy as np"
50 "import numpy as np\n",
51 "import sys"
51 52 ],
52 53 "language": "python",
53 54 "metadata": {},
@@ -58,7 +59,7
58 59 "cell_type": "code",
59 60 "collapsed": false,
60 61 "input": [
61 "numpy.random.rand(10)"
62 "np.random.rand(10)"
62 63 ],
63 64 "language": "python",
64 65 "metadata": {},
@@ -113,7 +114,7
113 114 "cell_type": "code",
114 115 "collapsed": false,
115 116 "input": [
116 "print \"hi, stdout\""
117 "print(\"hi, stdout\")"
117 118 ],
118 119 "language": "python",
119 120 "metadata": {},
@@ -132,7 +133,8
132 133 "cell_type": "code",
133 134 "collapsed": false,
134 135 "input": [
135 "print >> sys.stderr, 'hi, stderr'"
136 "from __future__ import print_function\n",
137 "print('hi, stderr', file=sys.stderr)"
136 138 ],
137 139 "language": "python",
138 140 "metadata": {},
@@ -168,7 +170,7
168 170 "input": [
169 171 "import time, sys\n",
170 172 "for i in range(8):\n",
171 " print i,\n",
173 " print(i)\n",
172 174 " time.sleep(0.5)"
173 175 ],
174 176 "language": "python",
@@ -253,7 +255,7
253 255 "collapsed": false,
254 256 "input": [
255 257 "for i in range(50):\n",
256 " print i"
258 " print(i)"
257 259 ],
258 260 "language": "python",
259 261 "metadata": {},
@@ -329,7 +331,7
329 331 "collapsed": false,
330 332 "input": [
331 333 "for i in range(500):\n",
332 " print 2**i - 1"
334 " print(2**i - 1)"
333 335 ],
334 336 "language": "python",
335 337 "metadata": {},
@@ -862,6 +864,7
862 864 "cell_type": "code",
863 865 "collapsed": false,
864 866 "input": [
867 "from __future__ import print_function\n",
865 868 "import sys"
866 869 ],
867 870 "language": "python",
@@ -881,8 +884,8
881 884 "collapsed": false,
882 885 "input": [
883 886 "%%capture\n",
884 "print 'hi, stdout'\n",
885 "print >> sys.stderr, 'hi, stderr'"
887 "print('hi, stdout')\n",
888 "print('hi, stderr', file=sys.stderr)"
886 889 ],
887 890 "language": "python",
888 891 "metadata": {},
@@ -901,8 +904,8
901 904 "collapsed": false,
902 905 "input": [
903 906 "%%capture captured\n",
904 "print 'hi, stdout'\n",
905 "print >> sys.stderr, 'hi, stderr'"
907 "print('hi, stdout')\n",
908 "print('hi, stderr', file=sys.stderr)"
906 909 ],
907 910 "language": "python",
908 911 "metadata": {},
@@ -1033,13 +1036,13
1033 1036 "input": [
1034 1037 "%%capture wontshutup\n",
1035 1038 "\n",
1036 "print \"setting up X\"\n",
1039 "print(\"setting up X\")\n",
1037 1040 "x = np.linspace(0,5,1000)\n",
1038 "print \"step 2: constructing y-data\"\n",
1041 "print(\"step 2: constructing y-data\")\n",
1039 1042 "y = np.sin(x)\n",
1040 "print \"step 3: display info about y\"\n",
1043 "print(\"step 3: display info about y\")\n",
1041 1044 "plt.plot(x,y)\n",
1042 "print \"okay, I'm done now\""
1045 "print(\"okay, I'm done now\")"
1043 1046 ],
1044 1047 "language": "python",
1045 1048 "metadata": {},
@@ -1088,8 +1091,8
1088 1091 "collapsed": false,
1089 1092 "input": [
1090 1093 "%%capture cap --no-stderr\n",
1091 "print 'hi, stdout'\n",
1092 "print >> sys.stderr, \"hello, stderr\""
1094 "print('hi, stdout')\n",
1095 "print(\"hello, stderr\", file=sys.stderr)"
1093 1096 ],
1094 1097 "language": "python",
1095 1098 "metadata": {},
@@ -452,8 +452,9
452 452 "collapsed": false,
453 453 "input": [
454 454 "from IPython.display import HTML\n",
455 "from base64 import b64encode\n",
455 456 "video = open(\"animation.m4v\", \"rb\").read()\n",
456 "video_encoded = video.encode(\"base64\")\n",
457 "video_encoded = b64encode(video)\n",
457 458 "video_tag = '<video controls alt=\"test\" src=\"data:video/x-m4v;base64,{0}\">'.format(video_encoded)\n",
458 459 "HTML(data=video_tag)"
459 460 ],
@@ -88,6 +88,7
88 88 "cell_type": "code",
89 89 "collapsed": true,
90 90 "input": [
91 "from __future__ import print_function\n",
91 92 "import sys, time\n",
92 93 "\n",
93 94 "class ProgressBar:\n",
@@ -99,7 +100,7
99 100 " self.__update_amount(0)\n",
100 101 "\n",
101 102 " def animate(self, iter):\n",
102 " print '\\r', self,\n",
103 " print('\\r', self, end='')\n",
103 104 " sys.stdout.flush()\n",
104 105 " self.update_iteration(iter + 1)\n",
105 106 "\n",
@@ -196,7 +196,7
196 196 "input": [
197 197 "b = %R a=resid(lm(Y~X))\n",
198 198 "%Rpull a\n",
199 "print a\n",
199 "print(a)\n",
200 200 "assert id(b.data) == id(a.data)\n",
201 201 "%R -o a"
202 202 ],
@@ -227,8 +227,8
227 227 "%R d=resid(lm(Y~X)); e=coef(lm(Y~X))\n",
228 228 "%R -o d -o e\n",
229 229 "%Rpull e\n",
230 "print d\n",
231 "print e\n",
230 "print(d)\n",
231 "print(e)\n",
232 232 "import numpy as np\n",
233 233 "np.testing.assert_almost_equal(d, a)"
234 234 ],
@@ -320,10 +320,11
320 320 "cell_type": "code",
321 321 "collapsed": false,
322 322 "input": [
323 "from __future__ import print_function\n",
323 324 "v1 = %R plot(X,Y); print(summary(lm(Y~X))); vv=mean(X)*mean(Y)\n",
324 "print 'v1 is:', v1\n",
325 "print('v1 is:', v1)\n",
325 326 "v2 = %R mean(X)*mean(Y)\n",
326 "print 'v2 is:', v2"
327 "print('v2 is:', v2)"
327 328 ],
328 329 "language": "python",
329 330 "metadata": {},
@@ -437,7 +438,7
437 438 "collapsed": false,
438 439 "input": [
439 440 "v = %R print(summary(X)); X\n",
440 "print 'v:', v"
441 "print('v:', v)"
441 442 ],
442 443 "language": "python",
443 444 "metadata": {},
@@ -682,9 +683,9
682 683 "cell_type": "code",
683 684 "collapsed": false,
684 685 "input": [
685 "print seq1\n",
686 "print(seq1)\n",
686 687 "%R -i seq1 -o seq1\n",
687 "print seq1\n",
688 "print(seq1)\n",
688 689 "seq1[0] = 200\n",
689 690 "%R print(seq1)\n",
690 691 "seq1_view = %R seq1\n",
@@ -732,7 +733,7
732 733 "try:\n",
733 734 " %R -n nosuchvar\n",
734 735 "except Exception as e:\n",
735 " print e.message\n",
736 " print(e)\n",
736 737 " pass"
737 738 ],
738 739 "language": "python",
@@ -205,8 +205,8
205 205 "cell_type": "code",
206 206 "collapsed": false,
207 207 "input": [
208 "print error\n",
209 "print output"
208 "print(error)\n",
209 "print(output)"
210 210 ],
211 211 "language": "python",
212 212 "metadata": {},
@@ -297,7 +297,7
297 297 "cell_type": "code",
298 298 "collapsed": false,
299 299 "input": [
300 "print ruby_lines.read()"
300 "print(ruby_lines.read())"
301 301 ],
302 302 "language": "python",
303 303 "metadata": {},
@@ -121,10 +121,11
121 121 "cell_type": "code",
122 122 "collapsed": false,
123 123 "input": [
124 "from __future__ import print_function\n",
124 125 "from scipy.integrate import quad, trapz\n",
125 126 "integral, error = quad(f, 1, 9)\n",
126 "print \"The integral is:\", integral, \"+/-\", error\n",
127 "print \"The trapezoid approximation with\", len(xint), \"points is:\", trapz(yint, xint)"
127 "print(\"The integral is:\", integral, \"+/-\", error)\n",
128 "print(\"The trapezoid approximation with\", len(xint), \"points is:\", trapz(yint, xint))"
128 129 ],
129 130 "language": "python",
130 131 "metadata": {},
General Comments 0
You need to be logged in to leave comments. Login now