IDLE debugger questions

R

Roger Davis

Hi, I have some questions about the IDLE debugger. I am using the
2.6.6 bundle downloaded from python.org.

First, how do I debug a Python program that requires command-line
args? I usually run it with a command like

% test.py arg1 arg2 arg3

There seems to be practically no detailed IDLE debugger documentation
and I have been unable to figure out how to pass these arguments into
the debugger.

Second, some folk say you can set a breakpoint by right-clicking on
the desired line in the source window to get a popup menu. This does
not work for me on my MacBook (external 3-button USB mouse), it only
adds a line-break into the source code. Any suggestions?

Thanks!

Roger Davis
 
N

Ned Deily

Hi, I have some questions about the IDLE debugger. I am using the
2.6.6 bundle downloaded from python.org.

First, how do I debug a Python program that requires command-line
args? I usually run it with a command like

% test.py arg1 arg2 arg3

One way would be to add some initialization test code to the main module
to set sys.argv. Another way is to call idle from the command line:

$ /usr/local/bin/idle2.6 -h

USAGE: idle [-deins] [-t title] [file]*
idle [-dns] [-t title] (-c cmd | -r file) [arg]*
idle [-dns] [-t title] - [arg]*

-h print this help message and exit
-n run IDLE without a subprocess (see Help/IDLE Help for
details)

The following options will override the IDLE 'settings' configuration:

-e open an edit window
-i open a shell window

The following options imply -i and will open a shell:

-c cmd run the command in a shell, or
-r file run script from file

-d enable the debugger
-s run $IDLESTARTUP or $PYTHONSTARTUP before anything else
-t title set title of shell window

A default edit window will be bypassed when -c, -r, or - are used.

[arg]* are passed to the command (-c) or script (-r) in sys.argv[1:].

Examples:

idle
Open an edit window or shell depending on IDLE's configuration.

idle foo.py foobar.py
Edit the files, also open a shell if configured to start with
shell.

idle -est "Baz" foo.py
Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell
window with the title "Baz".

idle -c "import sys; print sys.argv" "foo"
Open a shell window and run the command, passing "-c" in
sys.argv[0]
and "foo" in sys.argv[1].

idle -d -s -r foo.py "Hello World"
Open a shell window, run a startup script, enable the debugger,
and
run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in
sys.argv[1].

echo "import sys; print sys.argv" | idle - "foobar"
Open a shell window, run the script piped in, passing '' in
sys.argv[0]
and "foobar" in sys.argv[1].
Second, some folk say you can set a breakpoint by right-clicking on
the desired line in the source window to get a popup menu. This does
not work for me on my MacBook (external 3-button USB mouse), it only
adds a line-break into the source code. Any suggestions?

Right-click (control-click) menus currently don't work in IDLE on OS X.
I hope to get that fixed eventually.
 
R

Roger Davis

Thanks for that info, Ned, I can now get the sys.argv[] list I need,
that's a big help! However, is there any other way to set a breakpoint
in idle that will work on Mac OS X, maybe entering a manual command
somewhere with a specified line number? Inability to set a breakpoint
is an absolute showstopper for me, the code I am trying to debug loops
way too much to be manually steppable in a human time frame.

I also spent a couple of hours trying to get ddd to work, and oddly
enough encountered a similar problem there. After downloading and
installing pydb I was able to get things to start up OK. You can set a
breakpoint, meaning that you can click on the source line and the
little stop sign icon pops up right there as expected, but when you
run the code the debugger just blows right by it like it's not even
there. Does anyone out there have a fix for this? It sounds like ddd
Python support is highly problematic at the moment, supposedly it
works only with pydb but pydb's author has apparently moved on to a
different debugger project (pydbgr?) that I suspect has little chance
of working with ddd just yet. If anyone has evidence to the contrary
please let me know!

Are there any Python debuggers with a decent GUI out there at all that
will work on a Mac with the following features: (i) ability to pass in
a sys.srgv[] list that the program would otherwise see without the
debugger, (ii) display local variables, (iii) single-step through the
source code, and (iv) set a breakpoint? I think I can live without
anything else for the moment.

Thanks!
 
N

Ned Deily

Thanks for that info, Ned, I can now get the sys.argv[] list I need,
that's a big help! However, is there any other way to set a breakpoint
in idle that will work on Mac OS X, maybe entering a manual command
somewhere with a specified line number? Inability to set a breakpoint
is an absolute showstopper for me, the code I am trying to debug loops
way too much to be manually steppable in a human time frame.

Sorry about the long delay in replying. It turns out that IDLE's
breakpoint facility is currently unusable on OS X when Python Tkinter is
built with Aqua Tk, the default on OS X. The reason: IDLE implements
the Set and Clear Breakpoints menu options through a context popup menu
but the popup menus don't work with Aqua Tk. On other systems, the
popup menus are bound to the Right mouse button. But on OS X, there's
no guarantee that there is more than one button (the Left) and, even if
there is, the button bindings are different for Aqua Tk. The net effect
is that you can't make the popup menus appear with or without a
three-button mouse or equivalent. As far as I can tell, this has been
an issue ever since Python started using Aqua Tk on OS X instead of X11
Tk, many releases ago.

I've opened an issue for the problem and supplied a patch to have IDLE
use Control-Click for popups on OS X as is common in other applications.

http://bugs.python.org/issue10404

Thanks for calling this problem to our attention!
 
C

cbrown

Are there any Python debuggers with a decent GUI out there at all that
will work on a Mac with the following features: (i) ability to pass in
a sys.srgv[] list that the program would otherwise see without the
debugger, (ii) display local variables, (iii) single-step through the
source code, and (iv) set a breakpoint? I think I can live without
anything else for the moment.

I'm very happy using the Eclipse IDE (available for Mac, PC and 'Nix)
with the pydev plug-in. It's free, well supported and well behaved,
and has all the debugging features you name and then some. It's also a
modern code editor with code-hinting, syntax highlighting, etc.

The only downside of Eclipse to me is its 'workspace' and 'project'
metaphors for file organization; which take a bit of getting used to,
particularly if you're used to just editing in a text editor, and then
running in Idle or a command line.

I still usually also have Idle open as well so I can test little code
snippets quickly and easily; but mostly I work in Eclipse.

Cheers - Chas
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top