how to pickle a lambda?
Kragen Sitaker
kragen at pobox.com
Mon Apr 29 18:17:58 EDT 2002
Alejandro Dubrovsky <s328940 at student.uq.edu.au> writes:
> yes, but that means saving the definition as a string everytime that the
> lambda is changed. i was looking for something "neater". eg for function
> variables, i can just save and restore the variables'.__name__ attribute.
> i was wondering if there was something similar for lambdas.
Unfortunately not. You can't marshal lambdas either.
Generally, you can refactor code that uses lambdas into code that uses
object methods; your closure data goes into object attributes, and
each lambda becomes a class. Or you can just use named functions,
especially if you don't have closure data.
More information about the Python-list
mailing list