Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pdb, traceback, sys
- def bombs():
- a = []
- print a[0]
- if __name__ == '__main__':
- try:
- bombs()
- except:
- type, value, tb = sys.exc_info()
- traceback.print_exc()
- pdb.post_mortem(tb)
- import traceback, sys, code
- def bombs():
- a = []
- print a[0]
- if __name__ == '__main__':
- try:
- bombs()
- except:
- type, value, tb = sys.exc_info()
- traceback.print_exc()
- last_frame = lambda tb=tb: last_frame(tb.tb_next) if tb.tb_next else tb
- frame = last_frame().tb_frame
- ns = dict(frame.f_globals)
- ns.update(frame.f_locals)
- code.interact(local=ns)
- python -m pdb -c continue myscript.py
- import sys
- def info(type, value, tb):
- if hasattr(sys, 'ps1') or not sys.stderr.isatty():
- # we are in interactive mode or we don't have a tty-like
- # device, so we call the default hook
- sys.__excepthook__(type, value, tb)
- else:
- import traceback, pdb
- # we are NOT in interactive mode, print the exception...
- traceback.print_exception(type, value, tb)
- print
- # ...then start the debugger in post-mortem mode.
- # pdb.pm() # deprecated
- pdb.post_mortem(tb) # more "modern"
- sys.excepthook = info
- testlist = [1,2,3,4,5, 0]
- prev_i = None
- for i in testlist:
- if not prev_i:
- prev_i = i
- else:
- result = prev_i/i
- PS D:> python -i debugtest.py
- Traceback (most recent call last):
- File "debugtest.py", line 10, in <module>
- result = prev_i/i
- ZeroDivisionError: integer division or modulo by zero
- >>>
- >>>
- >>> prev_i
- 1
- >>> i
- 0
- >>>
- python myscript.py arg1 arg2
- ipython --pdb myscript.py -- arg1 arg2
- python -m mymodule arg1 arg2
- ipython --pdb -m mymodule -- arg1 arg2
- import pdb ; pdb.set_trace()
- python -m pdb -c c <script name>
- python -m mymodule
- PYTHONPATH="." python -m pdb -c c mymodule/__main__.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement