-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger_recipes.py
executable file
·30 lines (26 loc) · 1.17 KB
/
debugger_recipes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
"""
Debugger recipes from Ch. 3 of Wes McKinney's Python for Data Analysis (First Edition). Recipes and descriptions are copied verbatim.
"""
import sys
def set_trace():
"""
Put `set_trace()` anywhere in your code that you want to stop and take a look around (e.g., right before an exception occurs).
Pressing `c` (continue) will cause the code to resume normally with no harm done.
"""
from IPython.core.debugger import Pdb
pdb = Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back)
def debug(f, *args, **kwargs):
"""
Enables you to invoke the interactive debugger easily on an arbitrary functional call.
Example: suppose we had written a function like
`def f(x, y, z=1):
tmp = x + y
return tmp/z`
and we wish to step through its logic. Ordinarily using `f` would look like `f(1, 2, z=3)`.
To instead step into `f`, pass `f` as the first argument to `debug` followed by the positional and keyword arguments to be passed to `f`:
`debug(f, 1, 2, z=3)`
"""
from IPython.core.debugger import Pdb
pdb = Pdb(color_scheme='Linux')
return pdb.runcall(f, *args, **kwargs)