在python 2.7.6中:
# the data i'm trying to pickle
>>> x[0:5]
[494.12804680901604, 641.9374923706055, 778.293918918919, 470.2265625, 237.21332017010934]
>>> y[0:5]
[236.99996948242188, 381.6793310733242, 685.0, 409.0909090909091, 658.0]
>>> z[0:5]
[23, 20, 98, 24, 78]
>>> holder = [x,y,z]
我怎么腌制:
with open('holderData.obj','wb') as f:
pickle.dump(holder,f)
f.close()
在python 3.6.2中
with open('holderData.obj','rb') as f:
d = pickle.load(f, encoding='bytes')
然而,这回归:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ValueError: could not convert string to float
我发现的唯一问题/答案与this issue, tells me to add the encoding='bytes'
bit相关,但在这种情况下不起作用。
泡菜本身print(repr(pickle.dumps(holder)))
:
'(lp0\n(lp1\nF494.12804680901604\naF641.9374923706055\naF778.293918918919\naF470.2265625\naF237.21332017010934\naF372.76081123737373\naF396.15337968952133\naF615.2265625\naF470.2265625\naF581.2155330882352\naF488.40675200803213\naF475.47189597315435\naF92.0511279585