Lambda alternative?
Duncan Booth
duncan.booth at invalid.invalid
Wed Apr 15 12:51:34 EDT 2009
Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
> Duncan Booth <duncan.booth at invalid.invalid> writes:
>> What exactly is your objection to using a named function here?...
>> Surely that would solve your pickle problem *and* give you more
>> meaningful tracebacks in your exceptions?
>
> I don't think it would help the pickle problem.
Why wouldn't you think that?
class material(object):
def __init__(self,density):
self.density=density
def airdensity(T):
return 100000/(287*T)
air=material(airdensity)
steeldensity=lambda T:interp(T,[0,1000],[7856,7813])
steel=material(steeldensity)
from pickle import dumps, loads
dumped = dumps(air)
t = loads(dumped)
print t # works fine
dumped = dumps(steel) # pickle.PicklingError: Can't pickle <function
# <lambda> at 0x0000000002C78A58>: it's not found as __main__.<lambda>
More information about the Python-list
mailing list