473,395 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1611
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.