Live data from Hacker News

PySnooper: Never use print for debugging again

github.com

41–50 of 175 posts

Re: PySnooper: Never use print for debugging again

#41
Is there an equivalent of Common Lisp's TRACE in the Python world?

IMO it is the most value for money (i.e. time and convenience) debugging tool I've used till now. Simply write (TRACE function1 function2 ...) in the REPL and you will get a nicely formatted output of arguments passed and value(s) returned for each invocation of the given functions. Another nice feature is that a deeper an invocation is in the stack the more it is indented -- so recursive functions are fairly easy to debug too.

You can't use it for everything but its sufficient most of the time.

PySnooper looks good, but it is inconvenient in a couple of ways:

1. It prints every line of the traced function -- most of the time this is overkill and not what one needs. 2. To snoop on a function you need to modify the source file. Not a deal breaker but you still have to remember to revert this.

Re: PySnooper: Never use print for debugging again

#42
Super neat project. I am a print debugger myself and will definitely use this at some point in the future. For scenarios where PySnooper might be overkill and you just want to see the value of specific variables, I wrote a port of the Rust `dbg` macro for both Python and Go that are pretty nifty when looking at values really quickly:

https://github.com/tylerwince/pydbg

https://github.com/tylerwince/godbg

Re: PySnooper: Never use print for debugging again

#43
For my Django projects the development server is werkzeug [1] and anywhere a break point is needed I'll add 1/0 in the code then hit refresh in the browser which pulls up an interactive debugger [2].

[1] https://django-extensions.readthedocs.io/en/latest/runserver...

[2] https://werkzeug.palletsprojects.com/en/0.15.x/debug/#using-...

Re: PySnooper: Never use print for debugging again

#45
Before clicking I was like: why would one not use pdb. With vim, python-mode, and 'find . -name "*.py"| entr python testcases.py', setting break point and re-running is painless.

I was wrong. Upon skimming, it seems a huge plus PySnooper have over pdb is auto inspecting states, sparing whole lot of manual typing

Re: PySnooper: Never use print for debugging again

#46

Interesting project, though I'd suggest losing the line about "can't be bothered to set one up right now" regarding a full debugger. (i)pdb is built in and is simple to use. Perhaps focus on what this can add rather than framing the project as something like a lazy alternative (especially when this may actually be harder to set up than throwing in "import pdb; pdb.set_trace()")? edit: spelling

I'm currently learning Python and a little bit of numerical analysis with jupiter notebooks. I currently don't know what I'm doing. Pysnooper looks like it could drop in nicely to give some much needed help.

Re: PySnooper: Never use print for debugging again

#47

Interesting project, though I'd suggest losing the line about "can't be bothered to set one up right now" regarding a full debugger. (i)pdb is built in and is simple to use. Perhaps focus on what this can add rather than framing the project as something like a lazy alternative (especially when this may actually be harder to set up than throwing in "import pdb; pdb.set_trace()")? edit: spelling

On the contrary I think the author is spot on. I can never be bothered to get the debugger going no matter how easy.

So why would installing another debugger be easier?

Re: PySnooper: Never use print for debugging again

#48
post #47

Earlier quoted context omitted.

On the contrary I think the author is spot on. I can never be bothered to get the debugger going no matter how easy.

So why would installing another debugger be easier?

But this isn't a debugger. It's just instrumenting a function with some very verbose logs.

Re: PySnooper: Never use print for debugging again

#49

Interesting project, though I'd suggest losing the line about "can't be bothered to set one up right now" regarding a full debugger. (i)pdb is built in and is simple to use. Perhaps focus on what this can add rather than framing the project as something like a lazy alternative (especially when this may actually be harder to set up than throwing in "import pdb; pdb.set_trace()")? edit: spelling

Not only that, but if you're on Python 3.7 you can use breakpoint() without any imports, which is even shorter.

Re: PySnooper: Never use print for debugging again

#50

Interesting project, though I'd suggest losing the line about "can't be bothered to set one up right now" regarding a full debugger. (i)pdb is built in and is simple to use. Perhaps focus on what this can add rather than framing the project as something like a lazy alternative (especially when this may actually be harder to set up than throwing in "import pdb; pdb.set_trace()")? edit: spelling

Sometimes using a debugger isn’t always the best way. Sometimes you want to print out and examine lots of data taken from multiple runs/loop iterations and it’s simply easier to consume that information when it’s sitting in front of you all at once.
Post reply on HN