[Python-ideas] Addition to operator module: starcaller

Emanuel Barry vgr255 at live.ca
Thu Jul 21 10:19:46 EDT 2016


Hello,
You’re presumably doing something like ‘star = starcaller(f); star((“foo”, “bar”, “baz”))’ – how is it different from ‘f(*(“foo”, “bar”, “baz”))’ ? I don’t see any difference…

-Emanuel

From: Python-ideas [mailto:python-ideas-bounces+vgr255=live.ca at python.org] On Behalf Of Daniel Spitz
Sent: Thursday, July 21, 2016 10:07 AM
To: python-ideas at python.org
Subject: [Python-ideas] Addition to operator module: starcaller

Hello,

I have run into a use case where I want to create a wrapper object that will star-unpack a sequence of arguments to pass to a function. Currently one way to construct this is to create a function:

def starcaller(f):
    def wrapper(args):
        return f(*args)
    return wrapper

Such a function feels simple enough, and specific enough to the language, that it would fit in well in the operator module of the standard library. We already have a similar representation of this functionality in itertools.starmap.

Whereas the nested function implementation above will produce unpickleable objects (due to the closure), a straightforward c implementation will produce pickleable ones, making them useful for parallel applications.

Thanks,
Dan Spitz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160721/5a40dccc/attachment-0001.html>


More information about the Python-ideas mailing list