Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One of my favorite (ab)uses of operators is the "q" package for debugging: 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.



Just 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!


There 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 :-(


Aw, 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.


I use icecream: `ic(debug_expr)`. Not as concise, of course.


Please 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

Example:

    from icecream import ic

    def foo(i):
        return i + 333
    
    ic(foo(123))
Prints

    ic| foo(123): 456


Software library naming has always been terrible and mostly un-searchable, so links definitely help


For people who know how to use search engines, PP's version may be better since it wastes less vertical space on HN.


Thank you! I’ve been trying to remember this package’s name.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: