4 ms·
One of my favorite (ab)uses of operators is the "q" package for debugging: https://pypi.org/project/q/ https://pypi.org/project/q/ You `import q`, then you can
by nneonneo 5y ago
One of my favorite (ab)uses of operators is the "q" package for debugging: https://pypi.org/project/q/ https://pypi.org/project/q/
You `import q`, then you can slap `q/` or `q|` in front of an expression to log the value (q/ for high precedence, q| for low precedence). These days, `f"{x=}"` is probably preferred, but I still wind up using q occasionally because of its simplicity.
- Siira 5y agoI use icecream: `ic(debug_expr)`. Not as concise, of course.
- jaytaylor 5y agoPlease read the comment below in the gentlest, friendliest tone possible, because my goal is to considerately inform and persuade you, dear writer :) HTML links make it 10-100x more likely other readers will learn about the thing being mentioned (and thus help increase awareness and adoption of good tools and resources). https://github.com/gruns/icecream https://github.com/gruns/icecream Example: from icecream import ic def foo(i): return i + 333 ic(foo(123)) Prints ic| foo(123): 456
- jounker 5y agoThank you! I’ve been trying to remember this package’s name.
- ziml77 5y agoJust last week I was thinking that it would be great if Python had a way to print both the name and value of a variable without having to repeat the variable name. I checked the formatting mini-language spec and when I didn't see it there I assumed it didn't have it. I'm glad to know now that it does have that feature!
- renox 5y agoThere are several versions of the "the formatting mini-language" and the documentation that Google return first is for an old one which didn't have this feature :-(
- zestyping 5y agoAw, it's such a delight to open Hacker News and see this at the top of the comments! Glad you're enjoying q. I still use the @q decorator pretty often; it's really nice to be able to trace the arguments and return values of specific functions.