3

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

def a():
    private() # okay

def b():
    private() # raises error

def private():
    print "private"
4

1 回答 1

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"
于 2013-05-31T04:57:46.027 回答