how to pickle a lambda?

Paul Rubin phr-n2002a at nightsong.com
Sun Apr 28 20:13:58 EDT 2002


Alejandro Dubrovsky <s328940 at student.uq.edu.au> writes:
> def h(self):
> 	self.thelambdafunctiontobepickled = lambda x: self.t(x,4)
> 
> is there any simple way of pickling that lambda function above so that
> when i unpickle it will be set to the right function?

Lambdas are code objects which aren't portable between python
versions, so you can't pickle them.

If you want to serialize a code object so you can export and re-import
it to the same python version, use marshal rather than pickle.




More information about the Python-list mailing list