====== Python变量函数:函数名存在变量中 ====== 在PHP等语言中有变量函数(Variable Function)这一说法,意思就是将函数名存在变量中,然后根据变量值动态的调用需要的函数。 其实在Python中也有类似这样的功能。下面我们就来实现Python的变量函数。 ===== Python变量函数的实现 ===== def foo(): print 'hi' t = eval('foo') t() ===== 输出结果 ===== >>> def foo(): ... print 'hi' ... >>> t = eval('foo') >>> t() hi >>>