我已经使用了这种模式, 但我现在正在尝试将多个参数传递给函数 我应该添加另一个参数还是我的另一个语法片段 丢失?
def newChannel(hname, cname):
pass
action = {'newChannel': (newChannel, hname),
'newNetwork': (newNetwork, cname) , 'loginError': (loginError, nName)}
handler, param = action.get(eventType)
handler(param)
我怎么能通过多个参数呢? 像这样的......
action = { 'newChannel': (newChannel, hname, cname) }
是正确的吗?
编辑: 这会飞吗?
action = {'newChannelQueueCreated': (newChannelQueueCreated, (channelName, timestamp)), 'login':
(login, networkName), 'pushSceneToChannel': (pushSceneToChannel, channelName),
'channelRemovedFromNetwork': (channelRemovedFromNetwork, (channelName, timestamp))}
print ok
handler, getter = action.get(eventType(ok))
handler(*getter(ok))
答案 0 :(得分:6)
为什么不使用元组?
action = {'newChannel': (newChannel, (hname, cname)),
'newNetwork': (newNetwork, (cname,)),
'loginError': (loginError, (nName,))}
handler, params = action.get(eventType)
handler(*params)