Python显示函数的调用者

#!/usr/bin/env python
#coding:utf-8

import sys

def show_caller(level=1):
    def show(func):
        def wrapper(*args, **kwargs):
            func(*args, **kwargs)
            print '{0.f_code.co_filename}:{0.f_lineno}'.format(sys._getframe(level)), "->", func.__name__
        return wrapper
    return show

@show_caller(1)
def foo():pass

 

posted @ 2013-02-19 11:51  鸪斑兔  阅读(587)  评论(0编辑  收藏  举报