How to use includeContext of icecream module In Python
By configuring output as includeContext = True, the output will also print the parent function, filename, and the line number of the ic() which is executed.
Python3
# Python program to configure # prefix as parent function, # filename, and the line number from icecream import ic ic.configureOutput(includeContext = True ) def square(i): return ic(i) * i NUMBER = 2008 ic(NUMBER) ic(square( 23 )) |
Output:
$ python gfg.py" ic| 9.py:11 in <module>- NUMBER: 2008 ic| 9.py:7 in square()- i: 23 ic| 9.py:12 in <module>- square(23): 529
Debugging with ice cream in Python
Do you often use Python print() to debug your code? However, if you want to make a significant improvement, you could use IceCream which would make debugging faster, cleaner, and easier to read. ic(), which is short for IceCream prints both expressions/variable names and their values. ic() is faster to type than print(). The output is highlighted and printed in a structured format. If you want, you can include program context (filename, line number, and parent function) easily. You could effortlessly debug while solving competitive code problems and save a lot of time while debugging.
Contact Us