Pergunta

I have this pattern already in use, but I'm trying now to pass multiple parameters to the function should I just add another parameter or is there another syntactical piece I'm missing?

    def newChannel(hname, cname):
        pass

    action = {'newChannel': (newChannel, hname),
         'newNetwork': (newNetwork, cname) , 'loginError': (loginError, nName)}

    handler, param = action.get(eventType)
    handler(param)

How can i pass multiple params though? like such......

    action = { 'newChannel': (newChannel, hname, cname) } 

is that correct?

EDIT: Would this fly?

    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)) 
Foi útil?

Solução

Why not use a tuple?

action = {'newChannel': (newChannel, (hname, cname)),
          'newNetwork': (newNetwork, (cname,)),
          'loginError': (loginError, (nName,))}

handler, params = action.get(eventType)
handler(*params)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top