Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Visual Debugger [closed]

I know there are a thousand posts on debugging in Python but I can't find what I am looking for....a visual debugger. For example:

one@localhost ~ $ cat duh.py    
import pdb
class Coordinate(object):
     pdb.set_trace()
     def __init__(self, x, y):
         self.x = x
         self.y = y
     def __repr__(self):
         return "Coord: " + str(self.__dict__)
def add(a, b):
     return Coordinate(a.x + b.x, a.y + b.y)
def sub(a, b):
    return Coordinate(a.x - b.x, a.y - b.y)

one = Coordinate(100,200)
two = Coordinate(300,200)

add(one, two)

I want to see the values actually being used. Instead of seeing def __init__(self, x, y): I would like to see def __init__(self, 100, 200):

> /home/one/duh.py(14)<module>()
-> one = Coordinate(100,200)
(Pdb) s
--Call--
> /home/one/duh.py(4)__init__()
-> def __init__(self, x, y):
(Pdb) s
> /home/one/duh.py(5)__init__()
-> self.x = x
(Pdb) s
> /home/one/duh.py(6)__init__()
-> self.y = y
(Pdb) s
--Return--
> /home/one/duh.py(6)__init__()->None
-> self.y = y

I'm totally not used being blind on what is going on inside of the interpreter and really would like to see what is going on in the internals like other scripting language debuggers (like JavaScript step-throughs).

like image 346
dman Avatar asked May 10 '13 00:05

dman


People also ask

How do I close a Python debugger?

The Python debugger will automatically start over when it reaches the end of your program. Whenever you want to leave the pdb console, type the command quit or exit . If you would like to explicitly restart a program at any place within the program, you can do so with the command run .

How do I enable debugging in Python?

The debugger is enabled by default when the development server is run in debug mode. When running from Python code, passing debug=True enables debug mode, which is mostly equivalent. Development Server and Command Line Interface have more information about running the debugger and debug mode.

How do I turn off VS code debugger?

VS Code maintains a debug session while the program is running, and pressing the Stop button terminates the program.


1 Answers

That pdb debugging doesn't look like fun. I can see why you don't like it.

Fortunately, there are some visual Python debuggers out there. The two that I use most often are commercial products, but they are both well worth the cost. They are Komodo IDE and IntelliJ IDEA. These are multi-language IDEs that support many other languages in addition to Python. There is also a Python-only version of IDEA called PyCharm.

There's also a great free option, Winpdb. It's easy to use: once you install and open it, use File/Launch and enter the full path to your .py file, and then you can start debugging.

Those products are all multiplatform, but if you're on Windows another free option is Microsoft's Python Tools for Visual Studio. You can install this either into the commercial Visual Studio 2015 or the free Community Edition of Visual Studio 2015.

To give you an idea, here are screenshots of your code from Winpdb, Komodo and IDEA. I stepped into the __init__ function in each:

enter image description here  

enter image description here  

enter image description here

Don't worry if you don't like the code font I used; that's just my personal setting. And of course in normal use the screen is not so cramped; I made it small to fit in a screenshot.

I highly recommend any of these visual debuggers - it's great to be able to step through your code with a single keystroke and watch the variables change as you go.

like image 163
Michael Geary Avatar answered Oct 15 '22 13:10

Michael Geary