Python:如何在被调用的方法中获取调用者的方法名?
假设我有两种方法:
def method1(self):
...
a = A.method2()
def method2(self):
...
Run Code Online (Sandbox Code Playgroud)
如果我不想对method1进行任何更改,如何在method2中获取调用者的名称(在此示例中,名称为method1)?
如果你有两个功能,如:
def A
def B
Run Code Online (Sandbox Code Playgroud)
和A打电话给B,你能得到谁在B里面叫B,比如:
def A () :
B ()
def B () :
this.caller.name
Run Code Online (Sandbox Code Playgroud)