python获取
def anc():pass print anc.__name__ def timeit(func): def run(*argv): print "this function name is", func.__name__ if argv: ret = func(*argv) else: ret = func() return ret return run @timeit def add(anc): print anc add(1) for i in range(0,60): print("%02d"%i)
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()