Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91879

Re: for...else

From Laura Creighton <lac@openend.se>
Subject Re: for...else
References <CANFcO8tOLorV1kuGJo6Vgb-e02EhC3NL2U7oiNRNF+b2s2M2ig@mail.gmail.com> <1831776353.1951415.1433246463232.JavaMail.root@sequans.com><CANFcO8sQ0BjHU+7i6XEpaygZLhhi2R0zh0enNk4zk=L8QT3=kg@mail.gmail.com> <mailman.64.1433255400.13271.python-list@python.org><556dec13$0$3179$426a34cc@news.free.fr>
Date 2015-06-02 20:16 +0200
Newsgroups comp.lang.python
Message-ID <mailman.74.1433268978.13271.python-list@python.org> (permalink)

Show all headers | View raw


In a message of Tue, 02 Jun 2015 19:46:54 +0200, "ast" writes:
>
>
>"Laura Creighton" <lac@openend.se> a écrit dans le message de 
>news:mailman.64.1433255400.13271.python-list@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

yanked out of code I had lying around, without proper thought.
Sorry about that.

Laura

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: for...else Laura Creighton <lac@openend.se> - 2015-06-02 16:29 +0200
  Re: for...else "ast" <nomail@invalid.com> - 2015-06-02 19:46 +0200
    Re: for...else Laura Creighton <lac@openend.se> - 2015-06-02 20:16 +0200

csiph-web