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


Groups > comp.lang.python > #41037 > unrolled thread

Re: Switch statement

Started byMitya Sirenef <msirenef@lightbird.net>
First post2013-03-10 16:42 -0400
Last post2013-03-10 16:42 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#41037 — Re: Switch statement

FromMitya Sirenef <msirenef@lightbird.net>
Date2013-03-10 16:42 -0400
SubjectRe: Switch statement
Message-ID<mailman.3166.1362948152.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web