1{ 2 "cells": [ 3 { 4 "cell_type": "markdown", 5 "metadata": {}, 6 "source": [ 7 "# Using `raw_input` and `%debug` in the Notebook" 8 ] 9 }, 10 { 11 "cell_type": "markdown", 12 "metadata": {}, 13 "source": [ 14 "The Notebook has added support for `raw_input` and `%debug`, as of 1.0." 15 ] 16 }, 17 { 18 "cell_type": "code", 19 "execution_count": 1, 20 "metadata": { 21 "collapsed": false 22 }, 23 "outputs": [], 24 "source": [ 25 "# Python 3 compat\n", 26 "import sys\n", 27 "if sys.version_info[0] >= 3:\n", 28 " raw_input = input" 29 ] 30 }, 31 { 32 "cell_type": "code", 33 "execution_count": 2, 34 "metadata": { 35 "collapsed": false 36 }, 37 "outputs": [ 38 { 39 "name": "stdout", 40 "output_type": "stream", 41 "text": [ 42 "What is your name? Sir Robin\n" 43 ] 44 }, 45 { 46 "data": { 47 "text/plain": [ 48 "'Sir Robin'" 49 ] 50 }, 51 "execution_count": 2, 52 "metadata": {}, 53 "output_type": "execute_result" 54 } 55 ], 56 "source": [ 57 "name = raw_input(\"What is your name? \")\n", 58 "name" 59 ] 60 }, 61 { 62 "cell_type": "code", 63 "execution_count": 3, 64 "metadata": { 65 "collapsed": false 66 }, 67 "outputs": [ 68 { 69 "ename": "ZeroDivisionError", 70 "evalue": "division by zero", 71 "output_type": "error", 72 "traceback": [ 73 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 74 "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 75 "\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", 76 "\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", 77 "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" 78 ] 79 } 80 ], 81 "source": [ 82 "def div(x, y):\n", 83 " return x/y\n", 84 "\n", 85 "div(1,0)" 86 ] 87 }, 88 { 89 "cell_type": "code", 90 "execution_count": 4, 91 "metadata": { 92 "collapsed": false 93 }, 94 "outputs": [ 95 { 96 "name": "stdout", 97 "output_type": "stream", 98 "text": [ 99 "> \u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m(2)\u001b[0;36mdiv\u001b[1;34m()\u001b[0m\n", 100 "\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", 101 "\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", 102 "\u001b[0m\u001b[1;32m 3 \u001b[1;33m\u001b[1;33m\u001b[0m\u001b[0m\n", 103 "\u001b[0m\n", 104 "ipdb> x\n", 105 "1\n", 106 "ipdb> y\n", 107 "0\n", 108 "ipdb> bt\n", 109 " \u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m(4)\u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n", 110 "\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", 111 "\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", 112 "\u001b[0;32m 3 \u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 113 "\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", 114 "\u001b[0m\n", 115 "> \u001b[1;32m<ipython-input-4-a5097cc0c0c5>\u001b[0m(2)\u001b[0;36mdiv\u001b[1;34m()\u001b[0m\n", 116 "\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", 117 "\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", 118 "\u001b[0m\u001b[1;32m 3 \u001b[1;33m\u001b[1;33m\u001b[0m\u001b[0m\n", 119 "\u001b[0m\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", 120 "\u001b[0m\n", 121 "ipdb> exit\n" 122 ] 123 } 124 ], 125 "source": [ 126 "%debug" 127 ] 128 } 129 ], 130 "metadata": { 131 "kernelspec": { 132 "display_name": "Python 3", 133 "language": "python", 134 "name": "python3" 135 }, 136 "language_info": { 137 "codemirror_mode": { 138 "name": "ipython", 139 "version": 3 140 }, 141 "file_extension": ".py", 142 "mimetype": "text/x-python", 143 "name": "python", 144 "nbconvert_exporter": "python", 145 "pygments_lexer": "ipython3", 146 "version": "3.4.2" 147 } 148 }, 149 "nbformat": 4, 150 "nbformat_minor": 0 151} 152