Assigning a function (which is assigned dynamically) along with specific parameters, to a variable.
Question: Ok, so here's the deal, say I have a function( take_action ), that calls
another function. But we don't know which function take_action is going to
call.

I had that part figured out thanks to [this
question](http://stackoverflow.com/questions/4246000/python-calling-functions-
dynamically), the thing is, on that question they deal with functions that
take no arguments, my take_action could take one of several different
functions that are quite different from each other, with completely different
actions taken, different arguments.

Now for some example code:

    
    
    def take_action():
        action['action']()
        #does other stuff with 'other_stuff_in_the_dic'
    
    def move(x,y):
        #stuff happens
    
    action = {'action': move, 'other_stuff_in_the_dic': 'stuff' }
    

(In this case the 'action' would be move, but like I said, that's assigned
dynamically depending on certain user input)

What I would like to do, is something like this:

    
    
    action = { 'action': move(2,3), 'other_stuff': 'stuff' }
    

(Obviously that calls the function there, since it has the (), hence it
wouldn't work)

I'm only a beginner programmer, and the only thing I thought of is using a
list, which is in another key inside the dic, but that would just pass one
list argument, instead of each content of the list being passed on as an
argument.

What would be a way to achieve this, so the 'action' key (or the dictionary on
another key?) also stores the arguments it should use when I call it on
take_action?


Answer: Use
[`functools.partial()`](http://docs.python.org/3/library/functools.html#functools.partial)
to store functions with their arguments:

    
    
    from functools import partial
    
    action = {'action': partial(move, 2, 3), 'other_stuff': 'stuff'}
    

Calling `action['action']()` results in `move(2, 3)` being called.

