472,794 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

Debugging Python

What do people generally use to debug their Python programs? I haven't seen
anything out there that walks through the code, but perhaps I'm looking in
the wrong places?

TIA

Ashley

__________________________________________________ _______________
Tired of 56k? Get a FREE BT Broadband connection
http://www.msn.co.uk/specials/btbroadband
Jul 18 '05 #1
6 1585
Ashley Lloyd wrote:

What do people generally use to debug their Python programs? I haven't seen
anything out there that walks through the code, but perhaps I'm looking in
the wrong places?


When I need to, which is rare, I either use print statements (a very
solid technology dating from, oh, last century sometime ;-), or the
Python debugger module: pdb.

Actually, all I ever do with pdb is this:

# this is just before the code that I think is failing
import pdb
pdb.set_trace()

# code that I'm about to trace through goes here
And about the only features of pdb I've had to use are "r", "n", and
the ability to inspect arbitrary variables.

I'm not sure about others, but when I design and code using test-driven
development (TDD), I tend not to need to debug almost ever. The need
to debug is usually when you aren't sure where a typo, or logic error,
or other mistake has actually occurred. When using TDD, it's exceedingly
rare that when a test fails, I don't know exactly where the problem is
without having to resort to traditional (slow, tedious, annoying) debugging.

-Peter
Jul 18 '05 #2
Peter Hansen <pe***@engcorp.com> writes:
Ashley Lloyd wrote:

What do people generally use to debug their Python programs? I haven't seen
anything out there that walks through the code, but perhaps I'm looking in
the wrong places?


When I need to, which is rare, I either use print statements (a very
solid technology dating from, oh, last century sometime ;-), or the
Python debugger module: pdb.

Actually, all I ever do with pdb is this:

# this is just before the code that I think is failing
import pdb
pdb.set_trace()

# code that I'm about to trace through goes here
And about the only features of pdb I've had to use are "r", "n", and
the ability to inspect arbitrary variables.

I'm not sure about others, but when I design and code using test-driven
development (TDD), I tend not to need to debug almost ever. The need
to debug is usually when you aren't sure where a typo, or logic error,
or other mistake has actually occurred. When using TDD, it's exceedingly
rare that when a test fails, I don't know exactly where the problem is
without having to resort to traditional (slow, tedious, annoying) debugging.

-Peter

Interesting. A python newbie asked me the same thing yesterday and I
told him almost exactly what you said: If you are doing test-based
(whether or not it is with someojne else and thus Agile), you don't
get into those grim debug sessions that are part of life in C/C++
land.

Actually what I said was something like

"If you don't make mistakes, you don't need a debugger. The way to
avoid mistakes is to test everytime you edit a line or two of code.

"If you need to, use my homegrown debug statements (which print the
module and method/function name, the message, and then flush). If you
really get stuck, there is a debugger, but typically you just need
debuggers to solve memory problems. Python mistakes tend to be much
higher level, and pretty obvious once you see the data values."

--
ha************@boeing.com
6-6M31 Knowledge Management
Phone: (425) 342-5601
Jul 18 '05 #3
On Fri, 9 Jan 2004 10:29:46 GMT, Harry George
<ha************@boeing.com> wrote:
I'm not sure about others, but when I design and code using test-driven
development (TDD), I tend not to need to debug almost ever.
told him almost exactly what you said: If you are doing test-based
(whether or not it is with someojne else and thus Agile), you don't
get into those grim debug sessions that are part of life in C/C++
land.


Interesting comments. How do people generally perform these tests
then? My primary test tool, for low level testing, is usually the
debugger. Batch mode debugging is something I've been doing since
I worked on VAX/VMS systems and its seems as natural as breathing
to me. Its easy to save a test session and run it later etc. How
else do you test code at a low level?

Or does using the debugger as a test harness not count as
debugging?

Alan g
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
Jul 18 '05 #4
Alan Gauld wrote:
On Fri, 9 Jan 2004 10:29:46 GMT, Harry George
<ha************@boeing.com> wrote:

<think this was actually Peter in here>
I'm not sure about others, but when I design and code using test-driven
development (TDD), I tend not to need to debug almost ever.

....
Interesting comments. How do people generally perform these tests
then? My primary test tool, for low level testing, is usually the
debugger. Batch mode debugging is something I've been doing since
I worked on VAX/VMS systems and its seems as natural as breathing
to me. Its easy to save a test session and run it later etc. How
else do you test code at a low level?

Standard module unittest, although lots of people like doctest (closer
in spirit to your debugger debugging traces). The TDD/Agile people seem
generally to use the more formal unittest mechanism (which is more
appropriate when you're writing the test first), while doctest
encourages you to write something closer to a "regression" test, where
you're just testing that what works now isn't going to fail in the
future by recording side-effects (debugger/prompt output) and comparing
them to the later version's side-effects.

unittest testing is a rather involved thing, there's all sorts of
test-framework "fixtures", (e.g. MockObjects), that help you run a
particular method of a particular object all by its lonesome to test
that it does everything it is supposed to do and nothing it's not
supposed to do. The entire test-suite is supposed to be run regularly
(at least daily & before checkins), with local tests (those for the area
on which you are working) being run every 30 seconds or so as you write
new tests (and then the code to fix the breakage of those tests (and
that only if the test is actually broken with the current code-base)).

TDD (test-driven development) tends to reduce/eliminate the use of the
debugger because of that (automated) frequency of test-code-runs.
You're testing small blocks of code with tests whose very name says
what's failed about the block of code, so as soon as you screw something
up red lights start flashing telling you what you just did wrong. Given
that you're also *working* on very small code blocks, you generally know
what you just did (you aren't supposed to be coding large blocks of code
at once), and the failed tests' names tell you what went wrong (and
where) with what you just wrote.

I've only been able to rigorously apply TDD in one or two projects so
far. The fit for GUI and graphics code isn't spectacular (IMO).
Command-line, library, and network apps (with the appropriate test
fixtures (efficient use of which seems to be key to any serious use of
TDD)) seem to be a better fit.

Have fun,
Mike

_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/


Jul 18 '05 #5

"Alan Gauld" <al********@btinternet.com> wrote in message
news:3f****************@news.blueyonder.co.uk...
On Fri, 9 Jan 2004 10:29:46 GMT, Harry George Interesting comments. How do people generally perform these tests
then?


I use the unittest module.

It is *tedious* as hell to get the test cases up and running in unittest but
I find that it always takes less time and effort in total to take the pain
up front instead of debugging "later".

Often difficulties with the test code inspires one to rethink an interface
or a design, something one would not like to do on a larger collection of
code that "almost" runs.
Jul 18 '05 #6
Alan Gauld wrote:

On Fri, 9 Jan 2004 10:29:46 GMT, Harry George
<ha************@boeing.com> wrote:
I'm not sure about others, but when I design and code using test-driven
development (TDD), I tend not to need to debug almost ever.

told him almost exactly what you said: If you are doing test-based
(whether or not it is with someojne else and thus Agile), you don't
get into those grim debug sessions that are part of life in C/C++
land.


Interesting comments. How do people generally perform these tests
then? My primary test tool, for low level testing, is usually the
debugger. Batch mode debugging is something I've been doing since
I worked on VAX/VMS systems and its seems as natural as breathing
to me. Its easy to save a test session and run it later etc. How
else do you test code at a low level?

Or does using the debugger as a test harness not count as
debugging?


The debugger-as-test-harness does not count as testing, anyway, at
least not in the Agile sense. The tests *must* be automated, and
run very frequently (constantly) or you can't be very agile.

As others have said, the unittest is the key (in Python) or at least
the de facto standard. I would not agree that using it is "tedious"
at all, however, as it takes me only about twenty seconds to start a
new test file and that's *without* using a template. Running the tests
is also not tedious, at least not if you invest a few hours in a
simple utility that automates even the run-all-tests functionality.
I just type "unit -a" and all tests in all subfolders are immediately
run, without output going to a log file for later analysis in case
there are failures.

-Peter
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Humpty Dumpty | last post by:
Hello, I've been using python for about 3 months now. Prior to that I did C++ for over 5 years. I'm wondering if my debugging techniques are too C++ oriented. E.g., it took me about 9 hrs of...
8
by: beliavsky | last post by:
If I have some debugging code in a Python program (mostly print statements) and I want to turn it "off", two obvious methods are to (1) comment out the code (2) set a logical 'debug' variable at...
4
by: Jesper Olsen | last post by:
Hi, I have a C-extention build with distutils that I would like to debug. How can I specify to distuils to pass option "-g" and not "-O2" along to the compiler (gcc)? Jesper
0
by: peter | last post by:
Hello all, I would like to debug my python libraries, written in c++, with GDB (gnu debugger) I'm using the mingw compiler in a windows environment. As development environment I use eclipse...
1
by: jim.eggleston | last post by:
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...
4
by: diffuser78 | last post by:
I am a python newbie. I have writen some 500 lines of code. There are 4 classes and in all 5 files. Now, I am trying to run the program. I am getting wrong values for the simulation results. Is...
20
by: krypto.wizard | last post by:
Is there any editor or IDE in Python (either Windows or Linux) which has very good debugging facilites like MS VisualStudio has or something like that. I like SPE but couldn't easily use winPDP....
2
by: Gary Wessle | last post by:
Hi python users I am using emacs and python-mode.el under dabian testing. is there a way to debug python code where I can step over each line and watch the value of all the variables and be able...
4
by: dbee | last post by:
Right. I've got a really, really annoying/difficult/time consuming problem with my development environment. I'm using django to build a web app with paypal integration. My server is hosted...
2
by: Diez B. Roggisch | last post by:
Hi, I'm fiddling around with pydb. Installation and usage are fine. What I especially like is the fact that you can attach a signal such that you drop into debugging mode on demand. But this...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.