开发者

TypeError: 'str' does not support the buffer interface

开发者 https://www.devze.com 2023-03-27 18:03 出处:网络
i post from my original code, crystal = open(\'vmises.dat\',\'r\') crystalincrement=开发者_如何学C pickle.load(crystal)

i post from my original code,

crystal = open('vmises.dat','r')
crystalincrement  =开发者_如何学C pickle.load(crystal)
crystaldir = pickle.load(crystal)
crystalface = pickle.load(crystal)
crystal.close()

Error is,

crystalincrement  = pickle.load(crystal)

TypeError: 'str' does not support the buffer interface

i use python V 3.2


The real answer should be open the file in binary mode in windows. open('data.txt', 'rb')


The question was edited after I originally posted this and it was accepted. The answer to the updated question is to open the file in binary mode:

crystal = open('vmises.dat', 'rb')

Answer to original, pre-edit question:

Well, data is a string. The object you need to work on is a.

a = open('data.txt','r')
b = pickle.load(a) 
c = pickle.load(a)
d = pickle.load(a)
a.close()

For pickle info, see the Python Wiki or Python for Kids.


The pickle module loads a pickled object, which is a serialized version of a Python object. This code is trying to load a serialized data set into your program. You can read more about this module here: http://docs.python.org/library/pickle.html

I don't know where you've defined the variable data, but you probably want to load from the variable a, which is the pointer to a file which pickle takes in, or rename that variable to data.

data = open('data.txt','r')
b = pickle.load(data)
c = pickle.load(data)
d = pickle.load(data)
data.close()
0

精彩评论

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