3 ms·
Show HN: Python decorator to log local variables with each line of code run
- xLaszlo 3y agoWIP: suggestions most welcome.
- ttyprintk 3y agoHow does it compare to snoop: https://news.ycombinator.com/item?id=20457784 https://news.ycombinator.com/item?id=20457784
- awithrow 3y agonice, I do something similar with my tests to print out certain vars only when a test fails in order to get more context.
- cozzyd 3y agoWhat advantage does this have over a debugger? (To be fair, in my experience, lots of python users have no idea what a debugger is...)
- notnmeyer 3y agosame 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
- dr_kiszonka 3y agoIt is not unusual for me to have a for-loop running for a few hours as it is processing thousands of small objects or just a few dozen of large ones. A debugger wouldn't necessarily help me in this case and this decorator would be a little easier to set up than a logger.
- notnmeyer 3y agoah, yeah, i can see it being useful here.
- martinky24 3y agoLots of people still print debug. That’s ok.
- icholy 3y agoipdb.set_trace is the best of both worlds
- xLaszlo 3y agoThanks 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/ https://pypi.org/project/snoop/ it is more feature rich and maintained.
- JCharante 3y agoThis looks pretty cool. I think this would be faster than using a debugger when doing leetcode / timed puzzles