Python中是否有类似PHP的__FUNCTION__
魔术常数?
def func(x):
print(__FUNCTION__) ## <function func at 0x00B02810>
print(__FUNCTION__.__name__) ## func
升级版:
举个例子:
import sys
def func(f = "Foo"):
b = "Bar"
print(sys._getframe().f_code) ## <code object func at 0x00B09A20, file "C:\py\func.py", line 5>
print(func.__code__) ## <code object func at 0x00B09A20, file "C:\py\func.py", line 5>, the same
print(sys._getframe().f_trace) ## None
print(sys._getframe().f_locals) ## {'b': 'Bar', 'f': 'Foo'}
print(sys._getframe().f_lineno) ## 12
if __name__ == "__main__":
func()