[Tutor] Are you allowed to shoot camels? [kinda OT]

Smith, Jeff jsmith at medplus.com
Mon Feb 7 21:08:59 CET 2005


Alan,

That's actually worse than you might think.  Try this:

var = 'd'
def p(): pass
ftable = { 'a' : lambda: 'a',
           'b' : lambda: 'b or c',
           'c' : lambda: 'b or c',
           'd' : lambda: p}
print ftable.get(var, lambda: 'default case')()


And what you get is:
<function p at 0x009BDFB0>

That's hardly a pass :-)

Jeff

-----Original Message-----
From: Alan Gauld [mailto:alan.gauld at freenet.co.uk] 
Sent: Monday, February 07, 2005 3:06 PM
To: Smith, Jeff; Bob Gailer; tutor at python.org
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]



> That's kinda what I thought but a couple of people suggested
> that I used lambdas to make it clearer 

I suggested that if we had proper lambdas we could use 'em...

But of course you can still use lambdas just put the print 
at the client side:

def p(): pass
ftable = { 'a' : lambda: 'a',
           'b' : lambda: 'b or c',
           'c' : lambda: 'b or c',
           'd' : lambda: p}
print ftable.get(var, lambda: 'default case')()

But I still had to use a def for the pass... :-(

Alan G.



More information about the Tutor mailing list