Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Debugging Python ?

Reply
Thread Tools

Re: Debugging Python ?

 
 
Michael Sparks
Guest
Posts: n/a
 
      07-28-2003
On Mon, 28 Jul 2003, Shane Hathaway wrote:

> As a bonus, I find that print statements do not rightfully belong in
> most of the software I write. Therefore I can happily add print
> statements anywhere for debugging purposes, knowing that removing them
> later is perfectly safe.


As an extra bonus, if you do this you can remove them all automatically:

def print(*args):
for arg in args:
print arg,
return True


assert print("Well, well, well", "said", "he")

To erase all tracks of the debugging statements at runtime, just use the
-O flag. I tend to use a variant of this for debugging systems that have
"complex" concurrency to make it simpler to track "who" "said" what.

I know you can do the same with just grep if you use print - but you have
to ensure that your debugging statements don't span multiple lines.


Michael.


 
Reply With Quote
 
 
 
 
John Roth
Guest
Posts: n/a
 
      07-28-2003

"Michael Sparks" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 28 Jul 2003, Shane Hathaway wrote:
>
> > As a bonus, I find that print statements do not rightfully belong in
> > most of the software I write. Therefore I can happily add print
> > statements anywhere for debugging purposes, knowing that removing them
> > later is perfectly safe.


Yup. AFIC, the print statement is only for debugging, and it's quite
effective for that purpose.

> As an extra bonus, if you do this you can remove them all automatically:
>
> def print(*args):
> for arg in args:
> print arg,
> return True
>
>
> assert print("Well, well, well", "said", "he")
>
> To erase all tracks of the debugging statements at runtime, just use the
> -O flag. I tend to use a variant of this for debugging systems that have
> "complex" concurrency to make it simpler to track "who" "said" what.
>
> I know you can do the same with just grep if you use print - but you have
> to ensure that your debugging statements don't span multiple lines.


Which mine do, quite frequently. By the time you get this far,
you've pretty much got a logging system.

Another interesting arguement for the print statement versus
online debuggers is that, if you practice test driven development,
you gradually lose your facility with the debugger - you use it
so seldom.

John Roth
>
>
> Michael.
>
>



 
Reply With Quote
 
 
 
 
Keith Jones
Guest
Posts: n/a
 
      07-28-2003
On Mon, 28 Jul 2003 13:23:43 +0000, John Roth wrote:

>
> Yup. AFIC, the print statement is only for debugging, and it's quite
> effective for that purpose.
>


I would guess it's pretty good for teaching programming, too. Seeing

print "Hello world"

is more welcoming than even:

import sys
sys.stdout.write("Hello world\n")




 
Reply With Quote
 
Pedro Werneck
Guest
Posts: n/a
 
      07-28-2003
I use:

if __debug__: print "bla, bla, bla..."

And I was just wondering if it's legal to define a "print" function...
isn't print a keyword ?
 
Reply With Quote
 
Skip Montanaro
Guest
Posts: n/a
 
      07-29-2003
Pedro> And I was just wondering if it's legal to define a "print"
Pedro> function... isn't print a keyword ?

You're right. You'd need it to be Print or print_ or something similar.

Skip


 
Reply With Quote
 
logistix at cathoderaymission.net
Guest
Posts: n/a
 
      07-29-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Pedro Werneck) wrote in message news:<(E-Mail Removed). com>...
> I use:
>
> if __debug__: print "bla, bla, bla..."
>
> And I was just wondering if it's legal to define a "print" function...
> isn't print a keyword ?


Instead of defining "print" you can assign a custom class to
sys.stdout. Then all the print statements get automagically
redirected.:

if __debug__:
class newStdout:
def write(self,string):
print string
else:
class newStdout:
def write(self,string):
pass

import sys
sys.stdout = newStdout()
 
Reply With Quote
 
Anand Pillai
Guest
Posts: n/a
 
      07-29-2003
It would be nice if you could give a name
to your email address, i.e if you are not
that paranoid as it seems.

~Anand

(E-Mail Removed) (logistix at cathoderaymission.net) wrote in message news:<(E-Mail Removed). com>...
> (E-Mail Removed) (Pedro Werneck) wrote in message news:<(E-Mail Removed). com>...
> > I use:
> >
> > if __debug__: print "bla, bla, bla..."
> >
> > And I was just wondering if it's legal to define a "print" function...
> > isn't print a keyword ?

>
> Instead of defining "print" you can assign a custom class to
> sys.stdout. Then all the print statements get automagically
> redirected.:
>
> if __debug__:
> class newStdout:
> def write(self,string):
> print string
> else:
> class newStdout:
> def write(self,string):
> pass
>
> import sys
> sys.stdout = newStdout()

 
Reply With Quote
 
Aahz
Guest
Posts: n/a
 
      07-29-2003
In article <(E-Mail Removed) >,
Anand Pillai <(E-Mail Removed)> wrote:
>
>It would be nice if you could give a name to your email address, i.e if
>you are not that paranoid as it seems.


Top-posting is more annoying IMO. I remember e-mail addresses better
than names, anyway.
--
Aahz ((E-Mail Removed)) <*> http://www.pythoncraft.com/

This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz
 
Reply With Quote
 
Pedro Werneck
Guest
Posts: n/a
 
      07-29-2003
That's a nice idea... I done something similar to redirect print
statements to a text widget in a debug environment I am developing...
but my point here is not to redirect output... I think a statement
that simply does: if __debug__: print "..." would ease
debugging... that: def _print(*args): for arg in args:
print arg return True assert _print("bla", "bla bla") is very
interesting but it would be nice to have a standard way to do that...
a new statement, a modified assert statement or a new builtin... I am
not that experienced on python, so I don't know... what do you Python
gurus think ? Is this worth the effort ?
 
Reply With Quote
 
Alan Kennedy
Guest
Posts: n/a
 
      07-29-2003
Aahz wrote:

> Top-posting is more annoying IMO.


Aahz,

I know that you champion the cause of stopping people from
top-posting, and I agree that bottom-posting a good thing.

However, there is a down side: it makes it impossible to get
meaningful summaries of a posters posting history on Google Groups.
For example, here is your own history of posts:-

http://groups.google.com/groups?hl=e...z%40panix.com+

As you can see if you view that history, the summaries represented do
not contain what you actually said or wrote: they contain what other
people said, that you replied to. While this is generally not a
problem, you might find occasionally that it will appear, at the
summary level, that you said something that it is the precise opposite
of what you actually think or feel.

I don't have a solution, but I thought I would point out the problem.

regards,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I skip debugging Ajax when debugging my code? AAaron123 ASP .Net 3 07-28-2009 04:07 PM
Debugging C vs debugging C++ jacob navia C Programming 11 10-27-2006 07:19 PM
No Debugging of C# Server-Side Script, but Code-Behind Debugging Works Johann Blake ASP .Net 1 01-05-2004 03:01 PM
Debugging Python ? Bill Loren Python 2 08-02-2003 08:36 PM
Debugging a Python program from a browser Andrew Chalk Python 0 08-01-2003 04:01 PM



Advertisments