The nightmare called “print debugging”
I once spent hours just looking through the logs of an automation script. Every time the code failed, I would manually insert dozens of print() statements. The result? Logs filled with meaningless junk like “111”, “reached here”, “abc”… Finding the actual bug was like finding a needle in a haystack.
The problem is that while print() is easy to use, it becomes a burden as projects grow. You have to type variable names, format f-strings, and worst of all, spend more time finding and deleting them after the fix. After using Icecream in real-world projects for 6 months, I can say it’s a game-changer that saves at least 30% of debugging time daily.
What is Icecream and why is it so “sweet”?
Instead of writing print(f"my_variable: {my_variable}"), with Icecream, you only need three characters: ic(my_variable). This library does the heavy lifting: printing the variable name, its value, and the file/line of code being executed.
What made me “fall” for this library immediately is its self-inspecting capability. It doesn’t just show the result; it shows exactly which expression produced that value. Installation is lightning fast with a single command:
pip install icecream
Hands-on: From basic debugging to ‘enchanting’ your logging system
1. Inspect variables and expressions at warp speed
Look at the difference when you need to quickly check data. No messy formatting needed; Icecream knows what you want.
from icecream import ic
user_id = 1024
status = "active"
# Old way: typing until your hands hurt
print(f"user_id: {user_id}, status: {status}")
# With Icecream: Short and concise
ic(user_id, status)
The output looks incredibly professional: ic| user_id: 1024, status: 'active'. You can even throw in calculations or function calls:
def get_discount(price):
return price * 0.9
ic(get_discount(100) + 5)
Result: ic| get_discount(100) + 5: 95.0. As you can see, no need to rewrite the description string; Icecream understands and displays the entire original expression.
2. Check Execution Flow without ‘dropping’ variables
Have you ever wondered: “Wait, did the code even enter this Else branch?”. Instead of print("step 1"), just call ic() empty. It will report exactly which file, which line, and the execution time. This feature is extremely useful when debugging complex nested logic with dozens of branches.
3. Supercharging your Logging system
In production environments, we usually use logging instead of printing to the console. Icecream allows you to “pipe” debug results directly into your existing log files. Just configure it simply like this:
import logging
from icecream import ic
logging.basicConfig(level=logging.INFO)
ic.configureOutput(outputFunction=logging.info)
ic("Checking the system via logger")
Now, all detailed information from ic() will be neatly tucked into your system log files without changing your old management structure.
4. The 1-second code ‘cleanup’ trick
This is the feature that makes it worth every penny. Once you’ve fixed the bug and are ready to push code to the server, you don’t need to delete every ic() line. Just add ic.disable() in your main config file. Instantly, all debug commands go silent, returning a clean environment for production. Need to debug again? Just change it to ic.enable(). Done!
Real-world experience after 6 months of ‘fire testing’
I have almost completely abandoned the habit of using pprint or traditional print. However, to use Icecream most effectively, you should keep a few points in mind:
- Performance: Even with
ic.disable(), if placed inside loops running millions of times, it still incurs a small overhead. Consider this for large loops. - Sending notifications via API: If you want to get the formatted Icecream string to send via Telegram/Slack, use
ic.format(var)instead of printing directly. - Know when to stop: Icecream is great for quick data observation. But for deep logic bugs, the VS Code Debugger with breakpoints is still the gold standard.
In conclusion, if you’re still manually typing f-strings to debug, try Icecream right away. It’s like switching from handwriting to typing – faster, more professional, and completely effortless. Hope this little tip makes your workflow smoother.

