Skip to content

Instantly share code, notes, and snippets.

@dzil123
Created September 22, 2023 08:24
Show Gist options
  • Save dzil123/47789de98f5aab234eef57796a0593ef to your computer and use it in GitHub Desktop.
Save dzil123/47789de98f5aab234eef57796a0593ef to your computer and use it in GitHub Desktop.
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