检测调用函数名

#coding=utf8

import sys

def test():
    gf = sys._getframe
    print dir(gf())
    print 'function name:',sys._getframe(1).f_code.co_name
    if sys._getframe(1).f_code.co_name != 'a':
        print 'Error'
    else:
        print 'Ok'

 


def a():
    test()

def b():
    test()

class t(object):
    def a(self):
        test()

if __name__ == '__main__':
    a()
    b()
    tt = t()
    tt.a()

 

posted @ 2013-04-23 17:21  践道者  阅读(413)  评论(0编辑  收藏  举报