[Tutor] lambdas
Terry Carroll
carroll at tjc.com
Sun Dec 28 16:17:19 EST 2003
On Sat, 27 Dec 2003, Conrad Koziol wrote:
> How do you make a lambda expression that returns the time??
>
> I got this
>
> >>> lambda time: '%s-%s-%s: %s.%s:%s' % (time[0], time[1], time[2],
> time[3], time[4], time[5], time[6]), (time.localtime(time.time()))
>
> which returns this, which is not what I want.
>
> (<function <lambda> at 0x8a2791c>, (2003, 12, 27, 12, 30, 20, 5, 361,
> 0))
>
> i need something like 2003-15-03 1.45:45
I'm not sure you want lambda here. What's your context?
You can get the string you want like this, without resorting to lambda:
>>> import time
>>> '%s-%s-%s: %s.%s:%s' % time.localtime()[0:6]
'2003-12-28: 13.15:12'
[Aside: did you want the time part in form 13.15:12 or 13:15:12?]
--
Terry Carroll
Santa Clara, CA
carroll at tjc.com
More information about the Tutor
mailing list