Created
March 9, 2022 07:56
-
-
Save mborgerson/fa5238797891c045b5412f7ecc99c398 to your computer and use it in GitHub Desktop.
Find Python print culprit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hook the `print` built-in to find out where a print statement is coming from | |
import inspect | |
_print = print | |
def print(*vargs, **kwargs): | |
s = inspect.stack()[1] | |
_print(f'Printing from {s.filename}:{s.lineno}') | |
_print(*vargs, **kwargs) | |
import builtins | |
builtins.print = print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment