468,107 Members | 1,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

Debugging with SciTE

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

Oct 29 '05 #1
1 3527
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])

Oct 29 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Nuff Said | last post: by
3 posts views Thread by Brent W. Hughes | last post: by
32 posts views Thread by Sticks | last post: by
1 post views Thread by Grant Edwards | last post: by
1 post views Thread by Sandy | last post: by
4 posts views Thread by John Ladasky | last post: by
3 posts views Thread by SteveD | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.