Debugging with SciTE

J

jim.eggleston

I just figured out a reasonably decent way to use pdb in SciTE for
debugging Python scripts. Debugging takes place in the SciTE output
window. I have only tested this with SciTE on Windows.

Here are the pieces you need:

1. Create a debug.py script file (I save this in
c:\usr\python\scripts):
import sys
from pdb import pm, set_trace
from inspect import getmembers
if sys.platform == 'win32':
import os
os.environ['HOME'] = os.path.join(os.environ['HOMEDRIVE'],
os.environ['HOMEPATH'])
del sys.argv[0]
execfile(sys.argv[0])

2. Create a .pdbrc file in HOME (optional, but very useful):
#Print instance variables (usage "pi classInst")
alias pi for k in %1.__dict__.keys(): print "%1."+k,"=",%1.__dict__[k]
#Print instance variables in self
alias ps pi self
#pprint locals
alias ppl pp locals()
#pprint globals
alias ppg pp globals()
#pprint getmembers
alias ppm pp getmembers(%1)

3. Modify the Build line of the Scite Python.properties file:
# Use python instead of pythonw on non-windows platforms
command.build.*.py=pythonw -i -u c:\usr\python\scripts\debug.py
"$(FileNameExt)"
command.build.subsystem.*.py=1

Now if you hit F7 when editing a Python script, output will be sent to
the
SciTE output window, after which you will see a python prompt. Assuming
there is an exception, entering pm() will start post-mortem debugging,
and you will see the (Pdb) prompt. You can then use pdb commands and
aliases to inspect variable values.

To set a break point in your script, enter set_trace() at the
appropriate point. This will fire up pdb, and you can use s (step) to
step through the code, and the aliases in .pdbrc to list values.

Use Ctrl-Break to kill the debugging session.

You have to be carefull how you type in the output window. Backspaces
tend to confuse things, so you need to make sure your typing is right
the first time. .pdbrc aliases help to reduce typing, so make use of
them.

Cheers,
Jim
 
J

jim.eggleston

Based on information from Jarek Zgoda in another thread on the Windows
USERPROFILE environment variable, debug.py should be:
import sys
from pdb import pm, set_trace
from inspect import getmembers
if sys.platform == 'win32':
import os
os.environ['HOME'] = os.environ['USERPROFILE']
del sys.argv[0]
execfile(sys.argv[0])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top