[portland] Dictionary To Switch Contexts
Rich Shepard
rshepard at appl-ecosys.com
Mon Mar 17 23:51:52 CET 2008
On Mon, 17 Mar 2008, Dylan Reinhardt wrote:
> Here's a simplified example of how that might work... hope this helps:
> ----
> def doA():
> pass
>
> def doB():
> pass
>
> switcher = {
> 'a': doA,
> 'b': doB
> }
>
> x = someFunction() # returns 'a' or 'b'
>
> switcher[x]()
> ----
>
> With obvious changes if you want to pass arguments, check switcher with
> .get(), etc.
Dylan,
I miss seeing how I can create a function to provide the value when given
the key. My code uses the item within the tuple (compList[0][4]) as the
dictionary's key, and I want to call the function whose name is the value of
that key.
And all this time I thought that I understood dictionaries. :-)
Thanks,
Rich
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
More information about the Portland
mailing list