Live data from Hacker News

Icecream: Never use print() to debug again in Python

github.com

21–30 of 271 posts

Re: Icecream: Never use print() to debug again in Python

#23

I am always going to use print to debug in every programming language I can until the day I die.

Actually rust has the functionality of Icecream as a buildin command "dgb" and you quickly find yourself using it over print

No doubt blatantly ripped off the venerable print_r :P

Re: Icecream: Never use print() to debug again in Python

#24

You can do the same thing with Python 3.8+ by using f-strings and just appending "=" to the variable name: >>> print(f"{d['key'][1]=}") d['key'][1]='one'

WHAT... Why ain't anybody talking about this? Brilliant!

It was “recently” introduced in Python 3.8. See sibling for link to issue tracker

Re: Icecream: Never use print() to debug again in Python

#27
post #6

I am sorry, but I am not going to pull in an external dependency just for this, especially not with the power of fstrings in newer python versions.

It's for debugging. Not something to depend on in released code. Put the import in your site initialization file and you won't even have to import it in the REPL.

Re: Icecream: Never use print() to debug again in Python

#28
If.uou use vscode, the [Puke-Debug](https://marketplace.visualstudio.com/items?itemName=Zorvalt....) extension is a nice alternative. It allows to easily insert and remove similar print statements, in multiple languages, without adding a dependencies to your project that you need to remove afterwards.

Re: Icecream: Never use print() to debug again in Python

#29

You can do the same thing with Python 3.8+ by using f-strings and just appending "=" to the variable name: >>> print(f"{d['key'][1]=}") d['key'][1]='one'

Thank you, I was unaware of this. While I have lost a talking point in favour of Julia – the `@show` macro – I am happy that my old friends over in Python land has access to some better ergonomics and can stop rubbing this in their face. ;)

    julia> x = 4711
    4711
    
    julia> @show x
    x = 4711
    4711

Re: Icecream: Never use print() to debug again in Python

#30

Why don't people just use a debugger? It boggles my mind that people live with print style debugging. Depending on the project, it can be such a timer waster and just plainly worse in all aspects. Especially in Pycharm for me, it is incredibly easy. Even when running over ssh in remote computers I can use my debugger.

They're not perfect substitutes for each other. And not every python script that you need to quickly debug is worth firing up a while IDE for. Especially if your IDE requires creating a project and such. I say this as someone who very much loves Visual Studio.
Post reply on HN