Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import dill
- import lmfit
- from collections import OrderedDict as od
- #%% 1) this works ####################################
- class test(object):
- def inside_func(*args):
- return
- def __init__(self):
- # check OrderedDict dill-pickleable (should be)
- self.d = od([])
- self.d.update({'func': self.inside_func})
- return
- t = test()
- with open('test.pkl', 'wb') as f:
- dill.dump(t, f)
- #%% 2) this also works ###############################
- def outside_func(*args):
- return
- class test(object):
- def __init__(self):
- # some dummy Parameters set
- self.p = lmfit.Parameters()
- self.p.add('var1')
- self.p.add('var2')
- # addition of 'func' to _asteval's symtable from outside class scope
- self.p._asteval.symtable['func'] = outside_func
- return
- t = test()
- with open('test.pkl', 'wb') as f:
- dill.dump(t, f)
- #%% 3) this doesn't work ###############################
- class test(object):
- def inside_func(*args):
- return
- def __init__(self):
- # some dummy Parmaeters set
- self.p = lmfit.Parameters()
- self.p.add('var1')
- self.p.add('var2')
- # addition of 'func' to _asteval's symtable from inside class scope
- if not any('func' == x for x in self.p._asteval.symtable.keys()):
- self.p._asteval.symtable.update({'func': self.inside_func})
- return
- t = test()
- with open('test.pkl', 'wb') as f:
- dill.dump(t, f)
Add Comment
Please, Sign In to add comment