perfectly serialize a function in python
问题 I found a considerable answer from this post: Is there an easy way to pickle a python function (or otherwise serialize its code)? however, the restored function seems slightly different from the original one, which fails my test. Here's the sample code: import marshal # serialize f1 = lambda x: x == 0 c1 = marshal.dumps(f1.func_code) # deserialize f2 = types.FunctionType(c1, globals()) # test c1 = marshal.dumps(f1.func_code) c2 = marshal.dumps(f2.func_code) assert c1 == c2 # fails Do you have