IceCream: a better way to handle debug statements
If you find yourself adding print
statements to help you debug:
print('input:', input)
output=some_function(input)
print('output', output)
Library IceCream aims to make this a simplier task.
As described in their documentation:
ic()
is like print()
, but better:
- It prints both expressions/variable names and their values.
- It’s 60% faster to type.
- Data structures are pretty printed.
- Output is syntax highlighted.
- It optionally includes program context: filename, line number, and parent function.
Using IceCream, the above statements would be:
from icecream import ic
ic(input)
output=some_function(input)
ic(output)
and would yield:
ic| input: 'hello world'
ic| foo(123): 'some result'
More examples can be found on the IceCream site