What does HackerNews think of PySnooper?

Never use print for debugging again

Language: Python

#124 in Python
Looks interesting I will definitely try this.

For those that find this interesting, you might also like pysnooper - I use it all the time.

https://github.com/cool-RR/PySnooper

https://python.plainenglish.io/pysnooper-stop-debugging-pyth...

Shameless plug: PySnooper is a debugging tool for Python that lets you debug in a way that's as easy as adding print statements, but gives you a lot more information automatically.

https://github.com/cool-RR/PySnooper/

HN thread: https://news.ycombinator.com/item?id=19717786

Funny, a few months back I added this sentence to PySnooper's readme:

"PySnooper is a poor man's debugger. If you've used Bash, it's like set -x for Python, except it's fancier."

https://github.com/cool-RR/PySnooper

I use PySnooper[1] when code behavior deviates inscrutably from my mental model. Like Icecream, PySnooper exhorts, "Never use print for debugging again." A simple example:

    import pysnooper

    @pysnooper.snoop()
    def add_up(numbers):
        total = 0
        for number in numbers:
            total += number
        return total

    add_up([123, 456])
When run, PySnooper prints the activity of the decorated function or method:

        $ python example.py
        Source path:... /home/joel/example.py
        Starting var:.. numbers = [123, 456]
        08:46:58.742543 call         4 def add_up(numbers):
        08:46:58.742692 line         5     total = 0
        New var:....... total = 0
        08:46:58.742722 line         6     for number in numbers:
        New var:....... number = 123
        08:46:58.742755 line         7         total += number
        Modified var:.. total = 123
        08:46:58.742787 line         6     for number in numbers:
        Modified var:.. number = 456
        08:46:58.742818 line         7         total += number
        Modified var:.. total = 579
        08:46:58.742847 line         6     for number in numbers:
        08:46:58.742876 line         8     return total
        08:46:58.742898 return       8     return total
        Return value:.. 579
        Elapsed time: 00:00:00.000405
[1] https://github.com/cool-RR/PySnooper
Nice article. In particular the -i flag seems really useful.

I'd like to add two packages I learned about recently that I like A LOT: pyrasite and PySnooper.

Use pyrasite to "attach" to an existing running Python process (i.e. you forgot to instrument the app, but it has a bug in it, how can you debug?) (1) Install pyrasite (2) Get the PID of the running process (3) Run `pyrasite dumpstackz0.py` where dumpstackz0.pycontains `import traceback; traceback.print_stack()` (4) The stacktrace will be printed in the stdout/stderr of the running application

Use PySnooper instead of print-debugging—just add a decorator to any python function to get detailed debug info like you normally would get from a full debugger: (A) code: https://github.com/cool-RR/PySnooper (B) pypi: https://pypi.org/project/PySnooper/ (C) talk: https://www.youtube.com/watch?v=XP5imOJc_TE (D) podcast: https://www.youtube.com/watch?v=VUZvgJJKor0