我发现了很多关于此的线程,但所有线程的问题都是命名空间。我的问题与命名空间无关。
一个小例子:
import cPickle as pickle
from uncertainties import Variable
class value(Variable):
def __init__(self, args, showing=False):
self.show = showing
Variable.__init__(self, args[0], args[1])
val = value((3,1), True)
print val.nominal_value, val.std_dev(), val.show
fobj = file("pickle.file", "w")
pickle.dump(val, fobj)
fobj.close()
fobj = file("pickle.file", "r")
val = pickle.load(fobj)
fobj.close()
print val.nominal_value, val.std_dev(), val.show
此代码的输出:
3.0 1.0 True
3.0 1.0
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
173 else:
174 filename = fname
--> 175 __builtin__.execfile(filename, *where)
/home/markus/pickle.py in <module>()
19 val = pickle.load(fobj)
20 fobj.close()
---> 21 print val.nominal_value, val.std_dev(), val.show
AttributeError: 'value' object has no attribute 'show'
命名空间在酸洗和解酸时是相同的。的所有属性uncertainties.Variable
都恢复了——只有我添加的一个“节目”被遗漏了。