gpt4 book ai didi

python - pickle, 'str' 不支持 python 中的缓冲区接口(interface)

转载 作者:行者123 更新时间:2023-11-30 23:30:05 25 4
gpt4 key购买 nike

好的,我有以下代码:

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

请帮忙

最佳答案

我假设您正在 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

关于python - pickle, 'str' 不支持 python 中的缓冲区接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20832612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com