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

356,936
0
2023-10-05に共有
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: 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)
  • @monkmcfunk
    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.
  • @davidrusca2
    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.
  • @BillyChan77
    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!
  • @doofsCat
    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.
  • @thetruth45678
    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.
  • @Syfmuna
    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. 😄
  • @davidfell5496
    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.
  • @MegaJohn144
    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.
  • @KenHolm
    Great insight. Always love your videos!
  • @adamewing3702
    This is very cool! Didn't know about it, but this looks super helpful. Thanks!
  • @benlpayne
    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.
  • @Tanger68
    Sounds like I'm calling goodbye() on print()! Thanks for the video mate, super handy
  • @RobertLugg
    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.
  • @themuslimview
    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()
  • @CodePhiles
    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.
  • @vani8109
    Only after hearing it a dozen times did I realize that the function ic() is supposed to be a pun "I see" lol
  • @masterds163
    Great! Thanks for all your work and great videos! 👍