Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # powerful_vars_tracking.py
- import re
- import sys
- from functools import wraps
- import inspect
- def track_all_changes(variables_to_track):
- def track_changes(func):
- @wraps(func)
- def wrapper(*args, **kwargs):
- frame = inspect.currentframe()
- result = func(*args, **kwargs)
- for k, v in frame.f_back.f_locals.items():
- if k in variables_to_track:
- print(f"Local {k}: {v}")
- for k, v in frame.f_back.f_globals.items():
- if k in variables_to_track:
- print(f"{func.__name__}() Global {k}: {v}")
- return result
- return wrapper
- module = sys.modules[__name__]
- for name, obj in inspect.getmembers(module):
- if re.sub(r'__[^>]*__', '', name):
- if inspect.isfunction(obj):
- setattr(module, name, track_changes(obj))
- track_all_changes(variables)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement