zoukankan      html  css  js  c++  java
  • python 获取当前运行的类名函数名inspect.stack()[1][3]

    import inspect

    def get_current_function_name():
        return inspect.stack()[1][3]
    class MyClass:
        def function_one(self):
            print "%s.%s invoked"%(self.__class__.__name__, get_current_function_name())
    if __name__ == "__main__":
        myclass = MyClass()
        myclass.function_one()

    动态获取当前运行的函数名很方便,特别是对于一些debug系统来说

    来自:http://blog.sina.com.cn/s/blog_798f21a00100ywg4.html
  • 相关阅读:
    【bzoj1010】[HNOI2008]玩具装箱toy
    bzoj 3173
    bzoj 1179
    bzoj 2427
    bzoj 1051
    bzoj 1877
    bzoj 1066
    bzoj 2127
    bzoj 1412
    bzoj 3438
  • 原文地址:https://www.cnblogs.com/hongrun/p/10402824.html
Copyright © 2011-2022 走看看