一個另一個函數的參數的方法,我知道這是有效的:如何通過接收參數,在Python
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
我同意'lambda'可所謂這裏(+1)。事實上,這就是GUI編程中的常用方法(例如'tkinter'),因爲您沒有辦法修改執行回調的函數。 – mgilson 2012-07-16 13:01:58