[英]Python logging module AttributeError: 'str' object has no attribute 'write'
[英]python pickle gives “AttributeError: 'str' object has no attribute 'write'”
當我嘗試腌制某些東西時,我得到一個AttributeError: 'str' object has no attribute 'write'
一個例子:
import pickle
pickle.dump({"a dict":True},"a-file.pickle")
生產:
...
AttributeError: 'str' object has no attribute 'write'
怎么了?
這是一個微不足道的錯誤: pickle.dump(obj,file)
接受一個file
對象,而不是文件名。
我需要的是:
with open("a-file.pickle",'wb') as f:
pickle.dump({"a dict":True},f)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.