0
with open('data', 'w') as f:
pickle.dumps({'foo':111},f)
an integer is required (got type _io.TextIOWrapper)
我该如何解决这个问题?
我很肯定An integer is required? open()事先没有被调用。 Python版本是3.6.2
with open('data', 'w') as f:
pickle.dumps({'foo':111},f)
an integer is required (got type _io.TextIOWrapper)
我该如何解决这个问题?
我很肯定An integer is required? open()事先没有被调用。 Python版本是3.6.2
pickle.dumps
转储obj
到它返回的字符串中。为了写入文件,您可能需要使用pickle.dump
(不含s)。
with open('data', 'wb') as f:
pickle.dump({'foo':111}, f)
另外,你也应该以二进制模式打开文件,因为pickle.dump
会写二进制数据。
我刚刚编辑的答案提到打开文件时的二进制模式。 –
[dumps'的第二个参数是_'protocol'_](https://docs.python.org/3/library/pickle.html#pickle.dumps)。你是不是指'pickle.dumps({'foo':111},f)'? –