-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
db4e79f
commit 086403a
Showing
3 changed files
with
54 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import inspect | ||
|
||
|
||
def get_grandparent_info(): | ||
# Get the grandparent frame (caller of the caller) | ||
depth = min(2, len(inspect.stack()) - 1) | ||
caller_frame = inspect.stack()[depth] | ||
caller_file = caller_frame.filename | ||
caller_line = caller_frame.lineno | ||
caller_func = caller_frame.function | ||
|
||
return f"at {caller_file}:{caller_line} in {caller_func}" | ||
|
||
|
||
def foo(): | ||
def bar(): | ||
print(get_grandparent_info()) | ||
|
||
bar() | ||
def main(): | ||
foo() | ||
|
||
if __name__ == '__main__': | ||
main() |
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