如何在 Python 中以字符串形式获取函数名
以下变体对于成员函数也能可靠工作:
func_name_example.py
def func_name(func):
"""
Get the name of a function.
"""
if hasattr(func, '__qualname__'):
return func.__qualname__
elif hasattr(func, '__name__'):
return func.__name__
else:
return repr(func)Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow