RE: Switch statement

2013-03-10 Thread Joseph L. Casale
> Or could you do something like: > > arguments_to_pass = [list of some sort] > switch.get(var, default)(*arguments_to_pass) Stevens lambda suggestion was most appropriate. Within the switch, there are functions called with none, or some variation of arguments. It was not easy to pass them in afte

Re: Switch statement

2013-03-10 Thread Terry Reedy
On 3/10/2013 11:18 AM, Steven D'Aprano wrote: On Sun, 10 Mar 2013 14:16:27 +, 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 choic

Re: Switch statement

2013-03-10 Thread Nicholas Cole
On Sun, Mar 10, 2013 at 8:42 PM, Mitya Sirenef 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

Re: Switch statement

2013-03-10 Thread Mitya Sirenef
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,

RE: Switch statement

2013-03-10 Thread Joseph L. Casale
> switch = {  > 'A': functools.partial(spam, a), > 'B': lambda b, c=c: ham(b, c), > 'C': eggs, > } >  > switch[letter](b) That's cool, never even thought to use lambdas. > functools.partial isn't always applicable, but when it is, you should > prefer it over lambda since it will

Re: Switch statement

2013-03-10 Thread Steven D'Aprano
On Sun, 10 Mar 2013 14:16:27 +, 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: > > >

Re: Switch statement (was: Lambda going out of fashion)

2005-01-03 Thread TZOTZIOY
On Thu, 23 Dec 2004 19:57:27 GMT, rumours say that rzed <[EMAIL PROTECTED]> might have written: [Why did PEP 275 stall?] >It seems to me that it was regarded as misguidod. QOTPE +1 (PE=Python Era) Oncoming Python book: "Hitchhiker's Guido to the Python Language" -- TZOTZIOY, I speak England v

Re: Switch statement (was: Lambda going out of fashion)

2004-12-23 Thread rzed
Skip Montanaro <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > > Stephen> { > Stephen> 'one': lambda x:x.blat(), > Stephen> 'two': lambda x:x.blah(), > Stephen> }.get(someValue, lambda x:0)(someOtherValue) > > One thing to remember is that function calls in Python are >