Operation of pickle in Blender 2.56

1k views Asked by At

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?

1

There are 1 answers

0
Lennart Regebro On BEST ANSWER

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')