【发布时间】:2012-07-16 12:50:26
【问题描述】:
我知道这是有效的:
def printValue():
print 'This is the printValue() method'
def callPrintValue(methodName):
methodName()
print 'This is the callPrintValue() method'
但是有没有办法将接收参数的方法作为另一个函数的参数传递?
这是不可能的:
def printValue(value):
print 'This is the printValue() method. The value is %s'%(value)
def callPrintValue(methodName):
methodName()
print 'This is the callPrintValue() method'
这是我得到的堆栈跟踪:
This is the printValue() method. The value is dsdsd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in callPrintValue
TypeError: 'NoneType' object is not callable
【问题讨论】: