Blender 2.56中pickle的操作
我正在使用 pySerial 从 Arduino(微控制器)获取数据。
数据存储在 pickle 文件中。它与 Blender 2.49 (python 2.7) 配合得很好。
现在,切换到 Blender 2.56 (python 3.2),我收到以下错误:
f=open('abc.dat','r')
with serial.Serial('COM31',9600) as port :
for i in range(0, 10):
x = port.read(size=1)
print(int(x))
y=pickle.load(f)
f.close()
f=open('abc.dat','w')
y.append(i)
pickle.dump(y,f)
f.close()
port.close()
error:
Python script error from controller "Python Script#CONTR#1":
Traceback (most recent call last):
File "256script1.py", line 18, in <module>
f.close()
File "C:\PROGRA~1\BLENDE~1\Blender\2.54\python\lib\pickle.py", line 1365, in l
oad
encoding=encoding, errors=errors).load()
ValueError: read() from the underlying stream did notreturn bytes
Blender Game Engine Finished
使用 pickle
时是否有任何操作更改?
I am using pySerial to get data from an Arduino (micro-controller).
The data are stored in a pickle file. It worked fine with Blender 2.49 (python 2.7).
Now, shifting to Blender 2.56 (python 3.2), I get the following error:
f=open('abc.dat','r')
with serial.Serial('COM31',9600) as port :
for i in range(0, 10):
x = port.read(size=1)
print(int(x))
y=pickle.load(f)
f.close()
f=open('abc.dat','w')
y.append(i)
pickle.dump(y,f)
f.close()
port.close()
error:
Python script error from controller "Python Script#CONTR#1":
Traceback (most recent call last):
File "256script1.py", line 18, in <module>
f.close()
File "C:\PROGRA~1\BLENDE~1\Blender\2.54\python\lib\pickle.py", line 1365, in l
oad
encoding=encoding, errors=errors).load()
ValueError: read() from the underlying stream did notreturn bytes
Blender Game Engine Finished
Are there any operational changes in the use of pickle
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您以文本模式打开文件,但对于泡菜,它应该以二进制模式打开。在 Python 2 中这并不重要(Windows 上除外),但在 Python 3 中却很重要。
应该是
You open the file in text mode, but for pickles it should be in binary mode. In Python 2 this doesn't matter (Except on Windows), but in Python 3 it does.
It should be