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


Groups > comp.lang.python > #91879

Re: for...else

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'keys,': 0.07; 'callable.': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.14; 'translate': 0.15; 'arg):': 0.16; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'message-id:@fido.openend.se': 0.16; 'received:89.233': 0.16; 'received:89.233.217': 0.16; 'received:89.233.217.133': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'skip:> 50': 0.16; 'somewhere.': 0.16; 'thought.': 0.16; 'laura': 0.18; 'cc:addr:python.org': 0.21; 'cc:2**1': 0.22; 'parameter': 0.22; 'tuples': 0.22; '2015': 0.23; 'header:In-Reply-To:1': 0.24; '+0200,': 0.27; 'dictionary': 0.29; 'received:se': 0.29; 'cc:no real name:2**1': 0.29; 'that.': 0.30; 'code': 0.31; 'skip:d 20': 0.32; 'point': 0.33; 'useful': 0.35; 'skip:{ 10': 0.36; 'subject:: ': 0.37; 'tue,': 0.38; 'some': 0.40; 'header:Message-Id:1': 0.62; 'more': 0.62; 'dans': 0.72; 'received:89': 0.80; 'around,': 0.84; 'lying': 0.91
To "ast" <nomail@invalid.com>
cc python-list@python.org, lac@openend.se
From Laura Creighton <lac@openend.se>
Subject Re: for...else
In-Reply-To Message from "ast" <nomail@invalid.com> of "Tue, 02 Jun 2015 19:46:54 +0200." <556dec13$0$3179$426a34cc@news.free.fr>
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>
MIME-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-ID <4140.1433268967.1@fido>
Content-Transfer-Encoding 8bit
Date Tue, 02 Jun 2015 20:16:07 +0200
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [89.233.217.130]); Tue, 02 Jun 2015 20:16:09 +0200 (CEST)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.74.1433268978.13271.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433268978 news.xs4all.nl 2884 [2001:888:2000:d::a6]:53933
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91879

Show key headers only | 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