Created
September 22, 2023 08:24
-
-
Save dzil123/47789de98f5aab234eef57796a0593ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import builtins | |
import inspect | |
import sys | |
_print = builtins.print | |
def trace_func(frame, event, arg): | |
for l in [frame.f_globals, frame.f_locals]: | |
if l.get("print") is not None and l["print"] is not _print: | |
_print(l["print"]) | |
l["print"] = None | |
return trace_func | |
def begin(): | |
frame = inspect.currentframe() | |
while frame: | |
frame.f_trace = trace_func | |
frame = frame.f_back | |
sys.settrace(trace_func) | |
begin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment