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


Groups > comp.lang.python > #41037

Re: Switch statement

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <msirenef@lightbird.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'args': 0.04; 'cure': 0.07; 'arguments,': 0.09; 'python:': 0.09; 'cleanly': 0.16; 'presume': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'statement': 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'switch': 0.32; 'to:addr:python-list': 0.33; 'requiring': 0.35; 'there': 0.35; 'add': 0.36; 'ability': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40
Date Sun, 10 Mar 2013 16:42:24 -0400
From Mitya Sirenef <msirenef@lightbird.net>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3
MIME-Version 1.0
To python-list@python.org
Subject Re: Switch statement
References <assp.0781b21545.f529f94d99404cefa9b832ebf57d2898@exch.activenetwerx.com>
In-Reply-To <assp.0781b21545.f529f94d99404cefa9b832ebf57d2898@exch.activenetwerx.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3166.1362948152.2939.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362948152 news.xs4all.nl 6943 [2001:888:2000:d::a6]:34065
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41037

Show key headers only | View raw


On 03/10/2013 10:16 AM, Joseph L. Casale wrote:
> I have a switch statement  composed using a dict:
 >
 >
 > switch = {
 > 'a': func_a,
 > 'b': func_b,
 > 'c': func_c
 > }
 > switch.get(var, default)()
 >
 >
 > As a result of multiple functions per choice, it migrated to:
 >
 >
 >
 > switch = {
 > 'a': (func_a1, func_a2),
 > 'b': (func_b1, func_b2),
 > 'c': (func_c, )
 > }
 >
 >
 >
 > for f in switch.get(var, (default, )):
 > f()
 >
 >
 > As a result of only some of the functions now requiring unique 
arguments, I presume this
 > needs to be migrated to a if/else statement? Is there a way to 
maintain the switch style with
 > the ability in this scenario to cleanly pass args only to some functions?
 >
 >
 > Thanks,
 > jlc

You can have two dictionaries; you can also add a flag:
     'a': (WITHARG, funca1, funca2)

  -m


-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

The cure for boredom is curiosity. There is no cure for curiosity.
Dorothy Parker

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


Thread

Re: Switch statement Mitya Sirenef <msirenef@lightbird.net> - 2013-03-10 16:42 -0400

csiph-web