-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
235 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Use the 'inspect' module to extract local variables from | ||
multiple stack frames. Useful for dynamic debugging. | ||
""" | ||
import inspect | ||
|
||
|
||
def snapshot(): | ||
"""Capture a snapshot of local variables from the current and outer stack frames | ||
where the 'snapshot' function is called. Returns a list of dictionaries, | ||
each mapping function names to their respective local variables. | ||
Excludes the global module context. | ||
""" | ||
local_vars = [] | ||
frame = inspect.currentframe().f_back | ||
|
||
while frame: | ||
if frame.f_code.co_name != "<module>": | ||
local_vars.append({frame.f_code.co_name: frame.f_locals}) | ||
frame = frame.f_back | ||
|
||
return local_vars |
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