title: python–sys._getframe获取函数名与调用者名
top: 43
date: 2022-09-06 11:02:05
tags:
- python
categories: - python
import sys
def funca():
print(sys._getframe().f_code.co_name) # 函数名
print(sys._getframe(0).f_code.co_name) # 函数名
print(sys._getframe(1).f_code.co_name) # 调用者名
print(sys._getframe().f_back.f_code.co_name) # 调用者名
funca()
"""output
funca
funca
<module>
<module>
"""