Debugging 101: Replace print() with icecream ic()
356,936
2023-10-05に共有
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
💼 Services 💼
💻 Freelancing & Tutoring: www.neuralnine.com/services
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: www.instagram.com/neuralnine
🐦 Twitter: twitter.com/neuralnine
🤵 LinkedIn: www.linkedin.com/company/neuralnine/
📁 GitHub: github.com/NeuralNine
🎙 Discord: discord.gg/JU4xr8U3dm
コメント (21)
-
You could do this all much quicker by just inserting the built in python debugger with the line "import pdb; pdb.set_trace()" where you would normally put your print statement. It will then start the debugger in your terminal and you can view and even change all variables during execution. It also helps finding exactly where your code is breaking as you're stepping through the code line by line. I can't recommend it enough.
-
You know, from 3.10 onward you can essentially do this without packages by doing print(f"{variable=}"). Putting an = after the thing you are formating makes it so that it tells you the name/calculation together with the value.
-
Not going to lie, I use A LOT of print statement to debug. This is very cool , learn something new and will start trying TODAY!
-
Learnt something useful today. Thanks, this is something I will probably use in my classes as debugging is what I do 99% of the time.
-
One of the first things I do in any new language is create a debugging system. Helps to get you confortable with the syntax and environment, and gives you the tools up front to progress more efficiently. This is nice, too.
-
Thanks so much, I'm constantly learning new things from your videos and it's like this video was made for me. I was feeling specifically targeted when you were talking about using print(a) and print(type(a)), etc. 😄
-
Interesting. Will check it out. The 'timing' of when the icecream output happens looks relevant and you didn't touch on the behaviour there. But a nice introduction. Thank you.
-
I just found out about ice cream a couple of days ago. It was just what I needed when I needed it. Right now, I am developing in Flask, which doesn't print to the console, unless you flush. Ice cream takes care on that.
-
Great insight. Always love your videos!
-
This is very cool! Didn't know about it, but this looks super helpful. Thanks!
-
I would suggest skipping ice cream and going straight to python logging. It give much more control over how/what logging in emitted. I have found on many projects that starting from day 1 with using logging, instead of print is a great idea. The only thing I see that ic does that other don't is the quick ability to wrap a lines of code in ic and get a decent print that can help quickly debug issues. That said a debugger could also solve that use case.
-
Sounds like I'm calling goodbye() on print()! Thanks for the video mate, super handy
-
Very useful. Don't worry about "professional" way. Log files and print statements are the way to debug large runtime programs.
-
Nice tip, I tried it and enjoy the results. I believe it will become my tool of choice.
-
Thanks so much. As a Python Data Engineer, this is incredibly useful
-
Very useful! I will be using it from now on changing my 25 year old habit of using print()
-
this is good to take debugging step by step, it reaches out to be complicated at the end, so I think it would be better to show the real level at the end, which is the built in debugger, where you can do all the debugging techniques ( breakpoints, tracing code line by line, viewing all variables..etc )
-
Lovely! I will use this in the project i'm working on currently.
-
Only after hearing it a dozen times did I realize that the function ic() is supposed to be a pun "I see" lol
-
Great! Thanks for all your work and great videos! 👍