• 运行代码的文件的名称
  • 运行代码的类的名称
  • 运行代码的方法的名称(类的属性)
  • 最佳答案

    这是每个示例:

    from inspect import stack
    
    class Foo:
        def __init__(self):
            print __file__
            print self.__class__.__name__
            print stack()[0][3]
    
    f = Foo()
    

    关于python - 如何使用Python获取当前文件,当前类和当前方法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/894088/

    10-14 04:25