学以致用

focus on Python , C++, and some interest in Go and R

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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系统来说

posted on 2011-06-14 15:10  Jerry.Kwan  阅读(20048)  评论(0编辑  收藏  举报