data-science-ipython-notebooks/python-data/pdb.ipynb

112 lines
2.3 KiB
Python
Raw Permalink Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/data-science-ipython-notebooks)."
]
},
{
"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": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"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]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}