Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.osn.de!diablo1.news.osn.de!137.226.75.22.MISMATCH!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.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.000 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; 'somewhere.': 0.16; 'laura': 0.18; 'cc:2**2': 0.20; 'cc:addr:python.org': 0.21; 'tuples': 0.22; 'header:In-Reply-To:1': 0.24; 'dictionary': 0.29; 'received:se': 0.29; 'cc:no real name:2**1': 0.29; 'skip:d 20': 0.32; 'point': 0.33; 'useful': 0.35; 'skip:{ 10': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'some': 0.40; 'header:Message-Id:1': 0.62; 'more': 0.62; 'received:89': 0.80 To: acdr cc: Jean-Michel Pichavant , python-list@python.org, lac@openend.se From: Laura Creighton Subject: Re: for...else In-Reply-To: Message from acdr of "Tue, 02 Jun 2015 14:52:21 +0200." References: <1831776353.1951415.1433246463232.JavaMail.root@sequans.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30674.1433255390.1@fido> Date: Tue, 02 Jun 2015 16:29:50 +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 16:29:52 +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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433255400 news.xs4all.nl 2825 [2001:888:2000:d::a6]:33980 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91845 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