Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Debugging Python ? (http://www.velocityreviews.com/forums/t320211-re-debugging-python.html)

Michael Sparks 07-28-2003 04:08 PM

Re: Debugging Python ?
 
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.



John Roth 07-28-2003 05:23 PM

Re: Debugging Python ?
 

"Michael Sparks" <zathras@thwackety.com> wrote in message
news:mailman.1059409013.10134.python-list@python.org...
> 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.
>
>




Keith Jones 07-28-2003 08:00 PM

Re: Debugging Python ?
 
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")





Pedro Werneck 07-28-2003 10:49 PM

Re: Debugging Python ?
 
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 ?

Skip Montanaro 07-29-2003 02:10 AM

Re: Debugging Python ?
 
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



logistix at cathoderaymission.net 07-29-2003 04:13 AM

Re: Debugging Python ?
 
pedro.werneck@bol.com.br (Pedro Werneck) wrote in message news:<ef72fb2b.0307281449.6b144be7@posting.google. 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()

Anand Pillai 07-29-2003 12:53 PM

Re: Debugging Python ?
 
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

logistix@cathoderaymission.net (logistix at cathoderaymission.net) wrote in message news:<3c91a864.0307282013.2acb2d1f@posting.google. com>...
> pedro.werneck@bol.com.br (Pedro Werneck) wrote in message news:<ef72fb2b.0307281449.6b144be7@posting.google. 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()


Aahz 07-29-2003 02:11 PM

Casting stones (was Re: Debugging Python ?)
 
In article <84fc4588.0307290453.52671e11@posting.google.com >,
Anand Pillai <pythonguy@Hotpop.com> 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 (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/

This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz

Pedro Werneck 07-29-2003 02:32 PM

Re: Debugging Python ?
 
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 ?

Alan Kennedy 07-29-2003 02:43 PM

Re: Casting stones (was Re: Debugging Python ?)
 
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


All times are GMT. The time now is 07:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.