有没有办法限制特定函数调用的函数?

时间:2013-05-31 04:48:46

标签: python

有没有办法限制特定功能调用的函数?

def a():
    private() # okay

def b():
    private() # raises error

def private():
    print "private"

1 个答案:

答案 0 :(得分:3)

import inspect
def private():
    cframe = inspect.currentframe()
    func = inspect.getframeinfo(cframe.f_back).function
    if func != 'a':
        print 'not allowed from ', func
    print "private"