Avoiding if..elsif statements

Fredrik Lundh fredrik at pythonware.com
Fri Aug 25 19:33:15 EDT 2006


"unexpected" <sumesh.chopra at gmail.com> wrote:

> However, I'm passing in a few variables, so I can't just take it
> out-though every single function would be passing the same variables.
>
> so something.func() is actually
> something.func(string, list)
>
> How would I modify it to include them?

just add the parameters to the call:

    dispatch[value](string, list) # note: do the call here!

in Python, an explicit call is always written as

    expression(argument list)

where expression yields a callable object.  in your original case,
the expression was a bound method; in the modified example,
the expression is a dictionary lookup.  the actual call part looks
the same way, in both cases.

</F>






More information about the Python-list mailing list