Debugging
IceCream is a Python library that makes debugging easier and more efficient. With arguments, ic() inspects itself and prints both arguments and the values. Just give ic() a variable or expression and you are done.
from icecream import ic
def sum(x, y):
return x + y
dict = {'a': 1}
ic(sum(2,3))
ic(dict)
"""
ic| sum(2,3): 5
ic| dict: {'a': 1}
"""
Without Arguments
Without argumenst, ic() inspects itself and prints filename, line number and parent function. Jupyter doesn't output a new line with the value automatically, if we add a semicolon.
def myfunction():
ic()
return True
myfunction(); # semicolon at the end
"""
ic| 3877364280.py:2 in myfunction() at 10:24:00.200
"""
Disable Icecream
We can temporary disable ic(), and later re-enable. Icecream continues to return its arguments when disabled, of course.
ic(1)
ic.disable()
ic(2)
ic.enable()
ic(3);
"""
ic| 1
ic| 3
"""
Last update: 387 days ago