Skip to content

pya/pickablelambda

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pickable Lambda

Makes lambda pickleable!

I want to thank Mike Müller from Python Accademy for the interesting discussion on this topic and the smart ideas proposed to solve it!

Here is a simple example (see examples/simple_example.py):

import pickle

print("Define L = lambda x: x+1")
L = lambda x: x+1

print("Execute lambda")
print("L(10)=" + str(L(10)))


print("Try to pickle lambda...")
try:
    with open('lambda.pickle', 'wb') as f:
        pickle.dump(L, f)    
except:
    print(".. unfortunately lambdas are not picklable :-(")

print("But if you import pickablelambda and you wrap L with LambdaProxy...")

import pickablelambda 


with open('lambda.pickle', 'wb') as f:
    pickle.dump(pickablelambda.LambdaProxy(L), f)

print("... lambdas are pickable!")

About

Makes Python lambdas pickable!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%