Live data from Hacker News

Debugging Python Like a Boss

zapier.com

1–10 of 100 posts

Re: Debugging Python Like a Boss

#3
A good list of libraries, but please, don't use this in the middle of your code to set a break point:

    import pdb; pdb.set_trace();
There's a chance you forget this, check-in, and it ends in production. Use pdb facilities instead:

    $ python -m pdb 
Then set a breakpoint and continue:

    (Pdb) break :
    (Pdb) c
This is trivial to automate from any editor or command line, so you don't even have to guess the path to the file.

EDIT: For the lazy, here's a script to set breakpoints from the command line and run your scripts:

https://gist.github.com/hcarvalhoalves/7587621

Re: Debugging Python Like a Boss

#6
I've been using Python for a while for fun and Ruby (Rails) on and off.

I've always find it interesting how the Python/Ruby community debug your code both during development (coding or writing unit-tests) and perhaps in production as well (for the record, I use "print" as my debugging tool).

I'm a long time Eclipse user who has recently converted to IntelliJ (almost a year) and the debugger that comes with these editors is something I can't live without hence I have not moved to Emacs or VI(m) or whatever the UNIX hackers use because it would crippled my productivity significantly (or so I thought, feel free to criticize my point of view).

So sometimes I'm wondering how productive Python/Ruby + VIM/Emacs users. Just an honest question really.

PS: most Java IDE debuggers can do local AND remote AND has some support for hotswap code.

Re: Debugging Python Like a Boss

#7

A good list of libraries, but please, don't use this in the middle of your code to set a break point: import pdb; pdb.set_trace(); There's a chance you forget this, check-in, and it ends in production. Use pdb facilities instead: $ python -m pdb Then set a breakpoint and continue: (Pdb) break : (Pdb) c This is trivial to automate from any editor or command line, so you don't even have to guess the path to the file. E…

This is great advice, I didn't know there was a better way than the scary import/set_trace() method. Thanks for sharing!

Re: Debugging Python Like a Boss

#8

I've been using Python for a while for fun and Ruby (Rails) on and off. I've always find it interesting how the Python/Ruby community debug your code both during development (coding or writing unit-tests) and perhaps in production as well (for the record, I use "print" as my debugging tool). I'm a long time Eclipse user who has recently converted to IntelliJ (almost a year) and the debugger that comes with these edit…

You are doing it wrong, and you are making generalizations about these languages on the basis of your doing it wrong?

Re: Debugging Python Like a Boss

#9

A good list of libraries, but please, don't use this in the middle of your code to set a break point: import pdb; pdb.set_trace(); There's a chance you forget this, check-in, and it ends in production. Use pdb facilities instead: $ python -m pdb Then set a breakpoint and continue: (Pdb) break : (Pdb) c This is trivial to automate from any editor or command line, so you don't even have to guess the path to the file. E…

Thanks for the tip!

Re: Debugging Python Like a Boss

#10
post #4

very nice! plug: if you happen to be on windows, try PTVS which has nice features like mixed-mode Python/C++ debugging as well cross debugging from Visual Studio linux & MacOS. (it's a free plug-in). http://www.youtube.com/watch?v=wvJaKQ94lBY

Although VStudio Express does not support plugins, you can also use PTVS in combination with the free "VS2013 Shell" https://pytools.codeplex.com/wikipage?title=PTVS%20Installat...
Post reply on HN