我有困难完成以下功能:
def fullyQualifiedMethodNameInStack(depth=1):
"""
The function should return <file>_<class>_<method> for the method in the
stack at specified depth.
"""
fileName=inspect.stack()[depth][1]
methodName=inspect.stack()[depth][3]
class= """ please help!!! """
baseName=os.path.splitext( os.path.basename( fileName ) )[0]
return '{0}_{1}_{2}'.format( baseName, className, methodName )
正如你所看到的,我想要执行方法的类名。inspect返回的堆栈只有方法名,我不知道如何找到该方法所属的类。
inspect.stack()
似乎只能一致地返回函数名称,而不是函数对象。 - millimoose