Debuggers are cool and often necessary, but I disagree with this often-expressed sentiment that print-debugging is a primitive hack for people who don't know any better. Debugging is determining the point at which the program's expected behavior diverges from its actual behavior. You often don't know where where/when this is happening. Print-debugging can give you a transcript of the program's execution, which you ca…
Debugging Python Like a Boss
61–70 of 100 posts
Re: Debugging Python Like a Boss
#62Debuggers are cool and often necessary, but I disagree with this often-expressed sentiment that print-debugging is a primitive hack for people who don't know any better. Debugging is determining the point at which the program's expected behavior diverges from its actual behavior. You often don't know where where/when this is happening. Print-debugging can give you a transcript of the program's execution, which you ca…
>Debuggers are cool and often necessary, but I disagree with this often-expressed sentiment that print-debugging is a primitive hack for people who don't know any better. Yes. >Stepping through a program's execution line-by-line and checking your assumptions can be a lot slower in some cases. Yes again, particularly when the code is in a loop. Whereas, if you use print-debugging, even though the output will be repeat…
Re: Debugging Python Like a Boss
#63Earlier quoted context omitted.
>Debuggers are cool and often necessary, but I disagree with this often-expressed sentiment that print-debugging is a primitive hack for people who don't know any better. Yes. >Stepping through a program's execution line-by-line and checking your assumptions can be a lot slower in some cases. Yes again, particularly when the code is in a loop. Whereas, if you use print-debugging, even though the output will be repeat…
Um most debuggers allow you set variables and execute a loop n times
Re: Debugging Python Like a Boss
#64The most frustrating thing (experienced in both Javascript and Python) is the "oh uncaught exception? let me just quit everything" model. Most of the time, if I were just given an interactive prompt right then, I could spend 1 minute looking at local variables, maybe get a special stack trace variable to look at that, then be over with it. Instead I have to stick in some print statements and start everything over aga…
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt: # allow ctrl-C
raise
except Exception as e:
import sys, traceback, pdb
print e
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
This will catch any exceptions and throw you into PDB in the context where the exception was raised. You probably don't want to leave it in production code, but it's super useful for development.Re: Debugging Python Like a Boss
#65https://news.ycombinator.com/item?id=6770412
But I'm happy. When I posted, it failed to generate a discussion. If it were identified as a dupe this time, it would probably be forgotten.
It's a great article.
Re: Debugging Python Like a Boss
#66While in the subject of debugging Python you should look into Bugjar (gui) http://pybee.org/bugjar/ . Looks really good.
Re: Debugging Python Like a Boss
#67It's an early stage project, but hopefully demonstrates that there is a middle ground between "Everything in an 80x25 text window" and "500lb IDE gorilla".
(Full disclosure: I'm the core developer of Bugjar)
Re: Debugging Python Like a Boss
#68Re: Debugging Python Like a Boss
#69Once the weird behavior is covered, usually print debugging is even better than pdb because it will encourage you to extend the test suite.
What I would like though is a special monkey patching in python that allow my to write print like "p this that" and will prettyprint this and that on stdout
Re: Debugging Python Like a Boss
#70TL;DR , basically boiling down to: "There are debugger people, and then there are printf people, you see..."