1

我正在使用 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

4

1 回答 1

1

您以文本模式打开文件,但对于泡菜,它应该是二进制模式。在 Python 2 中这无关紧要(在 Windows 上除外),但在 Python 3 中确实如此。

它应该是

f=open('abc.dat','rb')
于 2011-02-27T21:12:12.147 回答