pickling lambdas?

John Roth newsgroups at jhrothjr.com
Sat Jan 3 18:55:11 EST 2004


"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote in message
news:7x65fs38cg.fsf at ruckus.brouhaha.com...
> "John Roth" <newsgroups at jhrothjr.com> writes:
> > > however, upon google searching for "python lambda pickle" i find 2
> > > posts, one including gvr, which apparently demonstrate that this was
> > > being attempted and even suggest that it is feasible.  has this become
> > > available yet, or will it be soon?
> >
> > Why do you want to do this? According to the docs, all that
> > is saved for a function or a class is the name. Code, data and
> > so forth is not saved, so it makes no sense to try to pickle
> > a lambda unless you've bound it to a name at the module level.
>
> I think the idea may be to pickle a closure, to save the data inside
> it.  I do remember some mention about pickling generators.  Anyway, in
> Python 2.x the closest you can come to that is pickling class
> instances.

That ought to work as long as you unpickle it into the same module
so you can get the original class definition.

John Roth





More information about the Python-list mailing list