Icecream: Never use print() to debug again in Python
171–180 of 271 posts
Re: Icecream: Never use print() to debug again in Python
#172I am always going to use print to debug in every programming language I can until the day I die.
Re: Icecream: Never use print() to debug again in Python
#173You 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'
You can also use the breakpoint() introduced in py3.7 via PEP533 https://www.python.org/dev/peps/pep-0553/
That said, sometimes you don't want to interrupt execution and see your results in real time.
Re: Icecream: Never use print() to debug again in Python
#174Re: Icecream: Never use print() to debug again in Python
#175Re: Icecream: Never use print() to debug again in Python
#176You 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'
You can also use the breakpoint() introduced in py3.7 via PEP533 https://www.python.org/dev/peps/pep-0553/
Re: Icecream: Never use print() to debug again in Python
#177Earlier quoted context omitted.
Absolutely, I don't understand why using print() or its equivalent in other languages is looked down upon. It's quick way to narrow down the "area of search" before bringing in the big guns.
Because you shouldn’t have to change code, just to debug it. It’s okay though to add verbose logging as a feature. But just adding some print statements to debug code and remove them afterwards, is dangerous (you release sth different than you debugged).
Re: Icecream: Never use print() to debug again in Python
#178Earlier quoted context omitted.
> Why don't people just use a debugger? I only speak for myself, but I find that time spent inside a debugger is "lost", and bound to be re-spent again and again if you ever find new problems with the same code. I pretty much prefer to add assertions, logging and comments to my program, that will stay there and make further re-reads easier and more useful. As a matter of principle, I never use a debugger (except for…
Then you are either using a bad debugger, or you're not using one properly. A good, fully-featured debugger allows you to store sessions and configurations for various efforts and problems you're trying to diagnose, along with your notes and links to relevant issues.
You are certainly right, as I barely ever use a debugger and it is always an annoying experience. Can you suggest such good debuggers for C, Julia and Python?
Sounds like these "sessions and configurations" are important, and thus they should be formally part of the program, committed to its public repository for all to see and use. I call these things "tests" and write them using the same language as the rest of the program, and run them frequently to be sure that they don't get out of sync with the program itself.
Re: Icecream: Never use print() to debug again in Python
#179I am always going to use print to debug in every programming language I can until the day I die.