Debugging in Py

N

*nixtechno

I'm just wondering if you all have any resources on Debugging that you
all would "recommend." Due to the fact I'm doing some debugging as a
beginner and this has the best of me, and I'm looking at trying to
learn more about what and how to debug within Py using print, and
etc...

There is so much out there in Google, I have a hard time on figuring
out where I should go and what I should be reading, because I been
trying everything under the sun, and seems I'm at a loss here. So
hopefully some of you can shed some light. Where I'm looking for a
great debug type of Cheat Sheet/tutorial.
 
T

Tim Chase

I'm just wondering if you all have any resources on Debugging that you
all would "recommend." Due to the fact I'm doing some debugging as a
beginner and this has the best of me, and I'm looking at trying to
learn more about what and how to debug within Py using print, and
etc...

For most of what I do, simply dropping a "print" line suffices.
For more complex stuff where I want to do a bit of on-the-fly
inspection, I'll often just add the line

import pdb; pdb.set_trace()

to my code and it will halt at a debugger prompt. You can then
use the batteries-included "pdb" debugger to inspect your
program's internal state.

You can read up on it at

http://docs.python.org/library/pdb.html#id1
http://www.oreillynet.com/pub/a/python/2005/09/01/debugger.html
http://www.ferg.org/papers/debugging_in_python.html

I use it mostly to dump variable contents and step into/over
lines of code (there are much deeper abilities that I hardly
scratch).

-tkc
 
N

*nixtechno

Big thanks tkc, and I was wondering what your thoughts are on logging
module: http://docs.python.org/library/logging.html

"Instead of using many print statements for debugging, use
logger.debug: Unlike the print statements, which you will have to
delete or comment out later, the logger.debug statements can remain
intact in the source code and remain dormant until you need them
again. At that time, the only change that needs to happen is to modify
the severity level of the logger and/or handler to debug."

Where it makes sense as they state using this rather than printing,
due to the fact that you don't have to strip it all out when it's time
to release your work... I seen some writing on pdb, but I guess it's
time to study up on it. I appreciate the help.
 
L

Lawson English

Jeremiah said:
On Wed, Mar 25, 2009 at 9:25 PM, *nixtechno <[email protected]

Big thanks tkc, and I was wondering what your thoughts are on logging
module: http://docs.python.org/library/logging.html

"Instead of using many print statements for debugging, use
logger.debug: Unlike the print statements, which you will have to
delete or comment out later, the logger.debug statements can remain
intact in the source code and remain dormant until you need them
again. At that time, the only change that needs to happen is to modify
the severity level of the logger and/or handler to debug."

Where it makes sense as they state using this rather than printing,
due to the fact that you don't have to strip it all out when it's time
to release your work... I seen some writing on pdb, but I guess it's
time to study up on it. I appreciate the help.
--
http://mail.python.org/mailman/listinfo/python-list


I really like the logging module. From the perspective of what you're
writing while you're working on part of an application, it tends to
not be that different that dropping print statements in, but there's a
wealth of flexibility and customizability available to you on the high
level.

For instance, I use it at work for one of our applications, and it
emails me whenever certain types of events occur that I need to know
about. It might be overkill for small projects, but it's definately
worth getting to know.
You can also redirect the logger output to various places like wx text
controls if you use the model
that wxPython itself uses to redirect print statements to its debug
console window. There's no end to
how you can use logger output if you work things this way since logger
refines its output based on a
hierarchical namespace that you can modify from any point in runtime.

E.G. direct errors and other text output from .THIS namespace logger to
..THIS text window or scrolling
list or logger file (or all of the above).


Lawson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top