views:

327

answers:

3

Hello,

I try Eclipse+PyDev pair for some of my work. (Eclipse v3.5.0 + PyDev v1.5.6) I couldn't find a way to expose all of my variables to the PyDev console (Through PyDev console -> Console for current active editor option) I use a simple code to describe the issue. When I step-by-step go through the code I can't access my "x" variable from the console. It is viewed on Variables tab, but that's not really what I want.

Any help is appreciate.

See my screenshot for better description:

alt text

EDIT:

Assume adding a simple func like:

def myfunc(x):
    return x**x

When I debug with the function added in the code I can access myfunc from the console easily. (Type myfunc and it will be available after this automatic execution:

>>> from part2.test import myfunc
>>> myfunc

Then when I do myfunc(5) it acts just like in the Python interpreter. It would be so useful to access variables in the similar fashion for debugging my code. I have big arrays and I do various tests and operations during debug process. Like: Get my x and do x.sum(), later do x[::10], or transpose operate with other arrays observe results, experiment etc...

Hope there will be a better solution.

A: 

See these answers:

Xavier Ho
OK, some looks useful. Still Debug console doesn't give the actual feeling of using Python interpreter where you can tab-complete and interact with variables/contents easily and conveniently.
Gökhan Sever
A: 

For this sort of exploratory debugging I like to use pdb, the batteries-included debugger. I haven't used it inside PyDev so I don't know how it would all fit together. My guess is it will do what you expect it to. An example of its usage:

import pdb

def myfunc(x):
    pdb.set_trace()
    return x**x

This will break right before executing the return statement, and it allows you to use full Pythonic statements to figure out what's going on. I use it like an interactive print statement: setting the place where I want to dive in, examining values and figuring results, and stepping through to watch it happen. Perhaps this is a lazy way of debugging, but sometimes you need more information before you can make less-lazy decisions :-)

The page I usually reference is at Python Conquers The Universe which also links a few other sources of information.

stw_dev
Thanks for the suggestion. It just little defeats the purpose of using Eclipse :) Jumping into definition of functions/methods is a great feature in Eclipse which more and more urges me staying in there rather than using IPython + VIM based development cycle. I am sure someone (Fabio maybe :) ) will suggest a way to inject my variables into local/global namespace while debugging in Eclipse.
Gökhan Sever
Note that you can do the same in PyDev in a breakpoint context (see http://pydev.org/manual_adv_debug_console.html).
Fabio Zadrozny
I wouldn't say it defeats the purpose... but I see your point. I checked and pdb works fine in PyDev, and it will indeed link to source when PyDev sees line-number annotations. Sorry PyDev hasn't caught up with general Eclipse usability, though I suspect it'll be much further a year from now.
stw_dev
+1  A: 

Unfortunately, the actual interactive console, which would be the preferred way of playing with code (with code-completion, etc -- http://pydev.org/manual_adv_interactive_console.html) has no connection to a debug session right now (this is planned but still not implemented).

Still, with the 'simpler' console available, you are still able to interactively inspect and play with the variables available in a breakpoint scope: http://pydev.org/manual_adv_debug_console.html (which is the same as you'd have with pdb -- it's just a matter of typing code in the available console after a breakpoint is hit).

Cheers,

Fabio

Fabio Zadrozny