{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# PDB\n", "\n", "The pdb module defines an interactive source code debugger for Python programs. Below are frequently used commands:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "invalid syntax (, line 5)", "output_type": "error", "traceback": [ "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m5\u001b[0m\n\u001b[0;31m python -m pdb script.py\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" ] } ], "source": [ "# Run pdb when this line is hit\n", "import pdb; pdb.set_trace()\n", "\n", "# Run pdb when the script is run\n", "python -m pdb script.py\n", "\n", "# Help\n", "h[elp]\n", "\n", "# Show current content\n", "l[ist]\n", "\n", "# Examine variables\n", "p[rint]\n", "\n", "# Pretty print\n", "pp\n", "\n", "# Go to next line\n", "n[ext]\n", "\n", "# Step into\n", "s[tep]\n", "\n", "# Continue execution until the line with the line number greater \n", "# than the current one is reached or when returning from current frame.\n", "until\n", "\n", "# Return\n", "r[eturn]\n", "\n", "# See all breakpoints\n", "b to see all breakpoints\n", "\n", "# Set breakpoint at line 16\n", "b 16 \n", "\n", "# Clear breakpoint 1\n", "cl[ear] 1\n", "\n", "# Continue\n", "c[ontinue]\n", "\n", "# Conditional breakpoints, line 11\n", "b 11, this_year == 2015\n", "\n", "# Stack location\n", "w[here]\n", "\n", "# Go up in stack\n", "u[p]\n", "\n", "# Go down in stack\n", "d[own]\n", "\n", "# Longlist shows full method of where you're in (Python 3)\n", "ll\n", "\n", "# Quit\n", "q[uit]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 1 }