开发者

Operation of pickle in Blender 2.56

开发者 https://www.devze.com 2023-02-13 13:15 出处:网络
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).

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?


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

f=open('abc.dat','rb')
0

精彩评论

暂无评论...
验证码 换一张
取 消