0

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)) 
sirvon
  • 2,547
  • 1
  • 31
  • 55

1 Answers1

6

Why not use a tuple?

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

handler, params = action.get(eventType)
handler(*params)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • exactly why not! perfect. – sirvon Jan 02 '14 at 10:26
  • action = {'newChannelQueueCreated': (newChannelQueueCreated, channelName), 'login': (login, networkName), 'pushSceneToChannel': (pushSceneToChannel, channelName), 'channelRemovedFromNetwork': (channelRemovedFromNetwork, (channelName, timestamp))} print ok handler, getter = action.get(eventType(ok)) handler(*getter(ok)) – sirvon Jan 02 '14 at 10:28
  • please see above edit ... would that fly b/c im unfamiliar with the (*params) – sirvon Jan 02 '14 at 10:30
  • I don't understand what that is supposed to be doing. The second value, which you've assigned to `getter`, seems to vary between a single value or a tuple - but either way you can't call it with `getter(ok)`, I don't understand what you are trying to do there. – Daniel Roseman Jan 02 '14 at 10:33
  • refer to this eariler question please....http://stackoverflow.com/questions/20838887/dispatch-dictionary-but-pass-different-parameters-to-functions – sirvon Jan 02 '14 at 10:36
  • yeah it was only accepting a single parameter but i'm trying to understand how to allow multiple parameters now. i'm pulling the parameters from a query string then using that value as a parameter. – sirvon Jan 02 '14 at 10:38