Tuple parameter unpacking in 3.x
Duncan Booth
duncan.booth at invalid.invalid
Sun Oct 5 05:43:24 EDT 2008
Martin Geisler <mg at daimi.au.dk> wrote:
> Letting the callbacks take several arguments would definitely be the
> nicest syntax, but I'm unfortunately restricted by the Twisted
> framework: there all functions in a callback chain return one result
> which is passed to the next callback as the first argument. That is why
> I do a fair amount of tuple unpacking in my code.
If you only have to contend with that one pattern then you could write a
decorator to unpack a single argument. Maybe not ideal, but then you have
the option to write:
@unpacked
def product(a, b):
return a*b
ci.addCallback(product)
or
ci.addCallback(unpacked(lambda a,b: a*b))
for some suitable definition of unpacked.
More information about the Python-list
mailing list