Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41039
| Return-Path | <nicholas.cole@gmail.com> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.034 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.00; 'args': 0.04; 'arguments,': 0.09; 'cleanly': 0.16; 'presume': 0.16; 'wrote:': 0.17; '>': 0.23; 'statement': 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'switch': 0.32; 'could': 0.32; 'like:': 0.33; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'requiring': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'ability': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; '2013': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=k4435CV/hi107EijRBQhSsaJIiyviknhvQgJV/fqtwQ=; b=Im20o+IRtf6MLjPFe2mOgVDNdTabwxVLUsaV0e/Hr2llV0/fgNp02/9ABcOLNN09c8 n2lmE6gTaZXIfl33QOeB3KW3YKgjSAxIvI7ryofsnFQgbOdXaNhipSFn189tFlQB8ZVp jQJ9z4nMLltwN4f9rYmjjpbStGDaWkGr7vPajDvXBd//5NwSrTwD6aiFyVoxZ0nYR2QT Z/9cmMWEA+JyfqHTVoRM5/2n4W7ipowF9PxPFcArozlkT5GiUJipHGzSviFmTIm+GinJ oldGCawr8HF+BkX1XweSK7sKc6w9MpJQMyn1pRCPp3kc8gQkB3Fji3Js3Ls3L2oYPzs5 NCaQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.224.17.198 with SMTP id t6mr14389308qaa.84.1362952219478; Sun, 10 Mar 2013 14:50:19 -0700 (PDT) |
| In-Reply-To | <513CF030.9030808@lightbird.net> |
| References | <assp.0781b21545.f529f94d99404cefa9b832ebf57d2898@exch.activenetwerx.com> <513CF030.9030808@lightbird.net> |
| Date | Sun, 10 Mar 2013 21:50:19 +0000 |
| Subject | Re: Switch statement |
| From | Nicholas Cole <nicholas.cole@gmail.com> |
| To | python-list@python.org |
| Content-Type | multipart/alternative; boundary=bcaec51dd8f1e3526d04d7990a72 |
| 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.3168.1362952228.2939.python-list@python.org> (permalink) |
| Lines | 103 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1362952228 news.xs4all.nl 6988 [2001:888:2000:d::a6]:49782 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!news.stben.net!goblin1!goblin3!goblin2!goblin.stu.neva.ru!xlned.com!feeder1.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:41039 |
Show key headers only | 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
Re: Switch statement Nicholas Cole <nicholas.cole@gmail.com> - 2013-03-10 21:50 +0000
csiph-web