检测调用函数名

#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()
原文地址:https://www.cnblogs.com/bjdxy/p/3038256.html