简体   繁体   English

泡菜错误-需要整数

[英]pickle error - integer required

with open('data', 'w') as f:
    pickle.dumps({'foo':111},f)

results in 结果是

an integer is required (got type _io.TextIOWrapper)

How can I fix this? 我怎样才能解决这个问题?

I am pretty sure An integer is required? 我很确定需要整数吗? open() was not called beforehand. open()未被事先调用。 Python version is 3.6.2 Python版本是3.6.2

pickle.dumps dumps obj into a string which it returns. pickle.dumpsobj转储到它返回的字符串中。 In order to write into a file, you probably want to use pickle.dump (without the s). 为了写入文件,您可能要使用pickle.dump (不带s)。

with open('data', 'wb') as f:
    pickle.dump({'foo':111}, f)

Additionally you should also open the file in binary mode, because pickle.dump will write binary data. 另外,您还应该以二进制模式打开文件,因为pickle.dump将写入二进制数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM