By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

Debugging with SciTE

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.