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


Groups > comp.lang.python > #41039

Re: Switch statement

References <assp.0781b21545.f529f94d99404cefa9b832ebf57d2898@exch.activenetwerx.com> <513CF030.9030808@lightbird.net>
Date 2013-03-10 21:50 +0000
Subject Re: Switch statement
From Nicholas Cole <nicholas.cole@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3168.1362952228.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Sun, Mar 10, 2013 at 8:42 PM, Mitya Sirenef <msirenef@lightbird.net>wrote:

> 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?
>

Or could you do something like:

arguments_to_pass = [list of some sort]
switch.get(var, default)(*arguments_to_pass)

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


Thread

Re: Switch statement Nicholas Cole <nicholas.cole@gmail.com> - 2013-03-10 21:50 +0000

csiph-web