是否可以将方法作为参数传递给方法?
self.method2(self.method1)
def method1(self):
return 'hello world'
def method2(self, methodToRun):
result = methodToRun.call()
return result
Run Code Online (Sandbox Code Playgroud) 我一直在使用工具来注册我的组件,但注意到了IWindsorInstaller.
它看起来与我相似,我想知道两者之间的区别是什么,应该在哪里使用.
将方法和方法参数传递给另一个方法的最佳方法是什么?
有没有更好的方法来做到以下几点?
def method1(name)
return 'Hello ' + name
def method2(methodToCall, methodToCallParams, question):
greetings = methodToCall(methodToCallParams)
return greetings + ', ' + question
method2(method1, 'Sam', 'How are you?')
Run Code Online (Sandbox Code Playgroud)