[Twisted-Python] pickle apparently doesn't go with curry ...

Glyph Lefkowitz glyph at twistedmatrix.com
Wed Nov 13 00:13:41 EST 2002

On Tue, 12 Nov 2002 12:06:07 -0500, Steve Waterbury <waterbug at beeblebrox.gsfc.nasa.gov> wrote:

> Any ideas?

Well, others have already told you why this doesn't work :-) but if I may
suggest something...

No offense to the very bright folks who brought us the Python Cookbook, because
I find much of it very valuable, but some of their recepies are overly
complicated with bizarre side effects that are really not obvious until you've
been using them for a while.  Persistence is a particularly dark corner, both
with pickle and without.  Two of my least favorite recipies in this regard are
"Borg" and "curry".  While interesting from a technical perspective on Python's
expressiveness, they're rarely expressing what you want :).  For example, to
translate the curry example you gave to a slightly-more-verbose but
much-more-straightforward python idiom:

class curry:
    def __init__(self, func, *create_time_args, **create_time_kwds):
        self.func = func
        self.create_time_args = create_time_args
        self.create_time_kwds = create_time_kwds
    def __call__(self, *call_time_args, **call_time_kwds):
        args = self.create_time_args + call_time_args
        kwds = self.create_time_kwds.copy()
        return self.func(*args, **kwds)

The cost of a much more straightforward interaction with other Python tools --
not just for persistence, but for example, for debugging -- comes to exactly 1
additional line of code.

 |    <`'>    |  Glyph Lefkowitz: Traveling Sorcerer   |
 |   < _/ >   |  Lead Developer,  the Twisted project  |
 |  < ___/ >  |      http://www.twistedmatrix.com      |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20021112/22948cee/attachment.pgp 

More information about the Twisted-Python mailing list