From 3610f54531a3d7e3ff731c1aba34b20ee369e221 Mon Sep 17 00:00:00 2001 From: Awin Huang Date: Wed, 12 Mar 2025 13:14:15 +0800 Subject: [PATCH] vault backup: 2025-03-12 13:14:15 Affected files: 20.01. Programming/Python/Get caller information.md --- .../Python/Get caller information.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 20.01. Programming/Python/Get caller information.md diff --git a/20.01. Programming/Python/Get caller information.md b/20.01. Programming/Python/Get caller information.md new file mode 100644 index 0000000..0f66a86 --- /dev/null +++ b/20.01. Programming/Python/Get caller information.md @@ -0,0 +1,23 @@ +--- +tags: +aliases: +date: 2025-03-12 +time: 13:10:38 +description: +--- + +```python +def getCallerInfo(msg): + callerFrame = inspect.currentframe().f_back + func_name = callerFrame.f_code.co_name + + class_name = "" + if 'self' in caller_frame.f_locals: + class_name = caller_frame.f_locals['self'].__class__.__name__' + + filename = os.path.basename(callerFrame.f_code.co_filename) + lineno = callerFrame.f_lineno +``` + + +# 參考來源 \ No newline at end of file