Re: list/dictionary as case statement ?
by Grant Edwards other posts by this author
Jan 2 2007 2:20PM messages near this date
Re: list/dictionary as case statement ?
|
Re: How do I add users using Python scripts on a Linux machine
On 2007-01-02, Stef Mientki <S.Mientki-nospam@[...].nl> wrote:
> If I'm not mistaken, I read somewhere that you can use
> function-names/references in lists and/or dictionaries, but
> now I can't find it anymore.
>
> The idea is to build a simulator for some kind of micro
> controller (just as a general practise, I expect it too be
> very slow ;-).
>
> opcodes ={
> 1: ('MOV', function1, ...),
> 2: ('ADD', function2, ),
> 3: ('MUL', class3.function3, )
> }
>
> def function1
> # do something complex
>
>
> Is this possible ?
Yes.
What you're implementing is commonly referred to as a
"dispatcher", and they're often done with a dictionary exactly
as you show.
--
Grant Edwards grante Yow! I guess you guys got
at BIG MUSCLES from doing too
visi.com much STUDYING!
--
http://mail.python.org/mailman/listinfo/python-list
Thread:
Stef Mientki
Bruno Desthuilliers
Bjoern Schliessmann
Tom Plunket
Stef Mientki
Bjoern Schliessmann
Mrab
Tom Plunket
Hendrik van Rooyen
Gary Herron
Stef Mientki
Grant Edwards
|