Pdb Python Cheat Sheet



  1. Python String Manipulation Cheat Sheet
  2. Python Pdb Tutorial
  3. Cheat Sheets For Python
  4. Ipdb Commands
  5. Python Pdb Commands

Python Debugger Cheatsheet Getting started importpdb;pdb.settrace startpdbfromwithinascript python-mpdb startpdbfromthecommandline Basics h(elp) printavailablecommands h(elp)command printhelpaboutcommand q(quit) quitdebugger Examine p(rint)expr printthevalueofexpr ppexpr pretty-printthevalueofexpr w(here) printcurrentposition(includingstacktrace). Python 3.7 break poi nt Start debugger inside a Python script PYTHO NBR EAK ‐ POI NT=0 Env Var: Set to skip all breakp oints PYTHO NBR EAK ‐ POI NT= ipd b.s ‐ et trace Env Var: breakp oint which debugger to use Getting Started import pdb;pd ‐ b.s et tra ce Start pdb inside a python script python -m pdb.

IPython / Jupyter¶

  • Using IPython makes interactive work easy.
    • Better shell
    • Notebook interface
    • Embeddable kernel
    • Parallel python

IPython shell shortcuts¶

  • TAB expansion to complete python names and file paths
  • ~ and * directory / file expansion
  • many 'magic' methods:

Help¶

%pdoc%pdef%psource for docstring, function definition, source code only.

Run¶

To run a program directly from the IPython console: Download soapui for mac.

%run has special flags for timing the execution of your scripts (-t) or for running them under the control of either Python's pdb debugger (-d) or profiler (-p):

Other Commands¶

  • %reset is not a kernel restart
  • Restart with Ctrl+. in 'qtconsole'
  • import module ; reload(module) to reload a module from disk

Debugging¶

OS Commands¶

History¶

GUI integration¶

Start with ipython --gui=qt or at the IPython prompt:

Python

Python String Manipulation Cheat Sheet

Arguments can be wx, qt, gtk and tk.

Matplotlib / pylab graphics in an iPython shell¶

Start with: ipython --matplotlib ( or --matplotlib=qt etc..)

Sheet

Python Pdb Tutorial

Pdb Python Cheat Sheet

At the IPython prompt:

Cheat Sheets For Python

%pylab makes the following imports:

At the command prompt:

alternative: --matplotlib inlineor within IPython:

To embed plots, SVG or HTML in qtconsole, call display:

Pdb Python Cheat Sheet

IPython Notebook web-based interface¶

Ipdb Commands

  • Start with: ipython notebook and switch to browser
  • Keyboard shortcuts:
    • Enter to edit a cell
    • Shift + Enter to evaluate
    • Ctrl + m or Esc for the 'command mode'

In command mode:

Python Pdb Commands

Papermill is a tool for parameterizing and executing Jupyter Notebooks.