Re: How to print lambda result ?

2009-01-21 Thread Steve Holden
f printing the lambda's object description. > Bye, > Ron. > > > -Original Message- > From: Tino Wildenhain [mailto:t...@wildenhain.de] > Sent: Tuesday, January 20, 2009 14:22 > To: Barak, Ron > Cc: python-list@python.org > Subject: Re: How to print lamb

Re: How to print lambda result ?

2009-01-20 Thread Terry Reedy
Tino Wildenhain wrote: or in python <3.0: (num,"s"*(num >1)) works fine in 3.0 too >>> num=1 >>> (num,"s"*(num >1)) (1, '') >>> num=2 >>> (num,"s"*(num >1)) (2, 's') Of course, 0 events gets 's' also, so (num!=1) is the actual comparison needed. -- http://mail.python.org/mailman/listinfo/

Re: How to print lambda result ?

2009-01-20 Thread Terry Reedy
Barak, Ron wrote: Thanks Tino: your solutions without the lambda work nicely. What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. You did not call it. -- http://mail.python.org/mailman/listinfo/

Re: How to print lambda result ?

2009-01-20 Thread alex23
On Jan 20, 10:57 pm, Tim Northover wrote: > Notice that there's no actual mention of num there, it's a function that > takes one parameter. If that parameter happens to be num it does what > you want, but there's no way for the interpreter to know what was > intended. Which is why my working exam

Re: How to print lambda result ?

2009-01-20 Thread D'Arcy J.M. Cain
On Tue, 20 Jan 2009 09:26:14 -0500 "D'Arcy J.M. Cain" wrote: > "%s" % lambda num: int(num) Of course I meant... "%s" % (lambda num: int(num)) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD

Re: How to print lambda result ?

2009-01-20 Thread D'Arcy J.M. Cain
On Tue, 20 Jan 2009 12:34:04 + "Barak, Ron" wrote: > Thanks Tino: your solutions without the lambda work nicely. > What I still don't understand is why the print does not execute the lambda > and prints the result, instead of printing the lambda's object description. Because that's what you

Re: How to print lambda result ?

2009-01-20 Thread Tim Northover
alex23 writes: > On Jan 20, 10:34 pm, "Barak, Ron" wrote: for num in range(1, 4): > ... string_ = "%d event%s" % (num, (lambda num: num > 1 and "s" or > "")(num)) > ... print string_ The notation here suggests Ron is sligtly confused about what he created. It was equivalent to st

Re: How to print lambda result ?

2009-01-20 Thread alex23
On Jan 20, 10:34 pm, "Barak, Ron" wrote: > What I still don't understand is why the print does not > execute the lambda and prints the result, instead of > printing the lambda's object description. The following two statements are identical: >>> def f(x): return x ... >>> f = lambda x: x lambda

RE: How to print lambda result ?

2009-01-20 Thread Barak, Ron
Ah, okay. Now it's clear. Thanks Tino. Ron. -Original Message- From: Tino Wildenhain [mailto:t...@wildenhain.de] Sent: Tuesday, January 20, 2009 14:45 To: Barak, Ron Cc: python-list@python.org Subject: Re: How to print lambda result ? Barak, Ron wrote: > Thanks Tino: your s

Re: How to print lambda result ?

2009-01-20 Thread Tino Wildenhain
ak, Ron Cc: python-list@python.org Subject: Re: How to print lambda result ? Hi, Barak, Ron wrote: Hi, Wanting to print the correct plural after numbers, I did the following: for num in range(1,4): string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "&qu

RE: How to print lambda result ?

2009-01-20 Thread Barak, Ron
[mailto:t...@wildenhain.de] Sent: Tuesday, January 20, 2009 14:22 To: Barak, Ron Cc: python-list@python.org Subject: Re: How to print lambda result ? Hi, Barak, Ron wrote: > Hi, > > Wanting to print the correct plural after numbers, I did the following: > > for num in range(1,4): > string_

Re: How to print lambda result ?

2009-01-20 Thread Tino Wildenhain
Hi, Barak, Ron wrote: Hi, Wanting to print the correct plural after numbers, I did the following: for num in range(1,4): string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") print string_ However, instead of getting the expected output: 1 event 2 events 3 events I get: