pickle,'str'不支持python中的缓冲区接口

时间:2013-12-30 02:45:57

标签: python

好的,我有以下代码:

def rate_of_work(self):
    global rate
    rate = (turtle.textinput("Your Work Rate","What is your hourly work rate in US Dollars?"))
    outFile_rate = pickle.dumps(rate)

rate1 = pickle.loads(rate)
rate2 = ((hours*rate1) + (minutes*rate1)*0.0167 + (seconds*rate1)*0.000278) #isnt necessary information
rate3 = round(rate2, 2) #isnt necessary information

我得到错误:

rate1 = pickle.loads(rate)
TypeError: 'str' does not support the buffer interface

请帮助

1 个答案:

答案 0 :(得分:3)

我假设你在python 3.x下工作

对于特定错误,pickle.loads()只接受字节,并且你试图给它一个纯字符串,这就是它失败的原因。

>>> pickle.loads("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' does not support the buffer interface
>>> pickle.loads(b"")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
EOFError