Navigate Select ESC Close

Debugging 101: Replace print() with icecream ic()

2023-10-05 Science & Technology
380.6k
11.9k
386
NeuralNine
NeuralNine
470.0k subscribers

Unlock all features

FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.

Description

Today we learn about the Python package called icecream, which you should use instead of print when debugging your code. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm

Top Comments (10)

@monkmcfunk 2023-10-17

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.

627 23 replies
@davidrusca2 2023-10-12

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.

343 17 replies
@doofsCat 2023-10-05

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.

209 8 replies
@thetruth45678 2023-10-05

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.

136 7 replies
@MrFlexNC 2023-10-08

People will move mountains so they don't have to use the logging package

17 3 replies
@stylish_vani 2023-12-28

Only after hearing it a dozen times did I realize that the function ic() is supposed to be a pun "I see" lol

11
@BillyChan77 2023-10-31

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!

10
@ConradoFonseca 2023-10-09

Why the output for result 30 appears/printed before the output for IC? @5:22 [EDITED] I just saw that this happens on every run, the IC output always comes after the program runs. I'm curious to know why.

4
@DeepeshSingh16 2024-06-08

this is very good bro thanks

1
@IRgEEK 2024-08-27

Nice improvement for logging. Thanks

0

Unlock the Data Inside
Turn Videos into Knowledge

  • Get FREE 10/day: transcripts, summaries, chats
  • Chat with videos, export text & PDF
  • $1 free API credit for RAG, chatbots & research

Free forever plan • All features unlocked

App screenshot