for...else

ast nomail at invalid.com
Tue Jun 2 13:46:54 EDT 2015


"Laura Creighton" <lac at openend.se> a écrit dans le message de 
news:mailman.64.1433255400.13271.python-list at python.org...
> You may be looking for dictionary dispatching.
>
> You can translate the key into a callable.
>
> def do_ping(self, arg):
>    return 'Ping, {0}!'.format(arg)
>
> def do_pong(self, arg):
>    return 'Pong, {0}!'.format(arg)
>
> dispatch = {
>    'ping': do_ping,
>    'pong': do_pong
> }
>
> and then at some point do
>
>    dispatch[command](arg)
>
> It is useful to know that tuples make perfectly good dictionary keys,
> in case you need to store more state somewhere.
>
> Laura

hello

Why "self" is as parameter of functions do_ping and do_pong ?

thx





More information about the Python-list mailing list