範例 :: Python Debugger

非侵入式的設定中斷點的偵錯方式 (以範例 :: Playground為基礎)

Expand 'sys.path' by adding environment variable 'PYTHONPATH'

export PYTHONPATH=mysite

Create a '.pdbrc' file in the same directory where manage.py resides.

# .pdbrc
b manage:10

Start development server

python -m pdb manage.py runserver

By default pdb will stop at the first statement:

Breakpoint 1 at /private/tmp/django-project/manage.py:10
> /private/tmp/django-project/manage.py(2)<module>()
-> import os

Press 'c', which is a pdb command

Now pdb will stop at the line #10 of the file manage.py:

> /private/tmp/django-project/manage.py(10)<module>()
-> execute_from_command_line(sys.argv)

Press 'c', which is a pdb command

Problem

You'd like to include Python scripts into my .pdbrc, but only pdb commands are allowed there.

Solution

Use execfile() to run a file containing your Python code. See detail

Problem

"import pdb; pdb.Pdb(skip=['django.*']).set_trace()"

Solution

n/a

results matching ""

    No results matching ""