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: 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" cc: python-list@python.org, lac@openend.se From: Laura Creighton Subject: Re: for...else In-Reply-To: Message from "ast" of "Tue, 02 Jun 2015 19:46:54 +0200." <556dec13$0$3179$426a34cc@news.free.fr> References: <1831776353.1951415.1433246463232.JavaMail.root@sequans.com> <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 In a message of Tue, 02 Jun 2015 19:46:54 +0200, "ast" writes: > > >"Laura Creighton" 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