Lazy argument evaluation (was Re: expression form of one-to-many dict?)
Nick Coghlan
ncoghlan at iinet.net.au
Wed Dec 22 08:03:59 EST 2004
Nick Coghlan wrote:
> def lazycall(x, *args, **kwds):
> """Executes x(*args, **kwds)() when called"""
> return lambda : x(*args, **kwds)()
It occurred to me that this should be:
def lazycall(x, *args, **kwds):
"""Executes x()(*args, **kwds) when called"""
return lambda : x()(*args, **kwds)
(Notice where the empty parens are)
Then this does the right thing:
lazycall(lazy(attrgetter('a'), x), y) # x.a(y)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list