top | item 38494986

Show HN: Python decorator to log local variables with each line of code run

42 points| xLaszlo | 2 years ago |pypi.org

13 comments

order

cozzyd|2 years ago

What advantage does this have over a debugger?

(To be fair, in my experience, lots of python users have no idea what a debugger is...)

xLaszlo|2 years ago

Thanks for the comments.

I don't have anything against debuggers, but I feel more natural to write into the code and this simplifies it.

TBH I haven't tried this or snoop heavily and the project was more of a curiosity of how the internals of python work after I found a relevant SO post.

Honestly I was surprised how easy it was.

If you actually want to use something like this use snoop: https://pypi.org/project/snoop/ it is more feature rich and maintained.

martinky24|2 years ago

Lots of people still print debug. That’s ok.

notnmeyer|2 years ago

same thoughts. i kind of get the utility of logging the whole application state without breakpoints or stepping through stuff (but maybe debuggers can also do this?), but my first thought was that this is simpler for folks not used to debuggers

icholy|2 years ago

ipdb.set_trace is the best of both worlds

JCharante|2 years ago

This looks pretty cool. I think this would be faster than using a debugger when doing leetcode / timed puzzles

awithrow|2 years ago

nice, I do something similar with my tests to print out certain vars only when a test fails in order to get more context.