我把模块pickle保存在我的目录中。 现在,我想将变量Arpan存储在一个名为spdict.data的创建文件中 所以,当我输入代码如下:
import pickle
Arpan = "My name is Arpan"
fh = open("spdict.data","w")
pickle.dump(Arpan,fh)
fh.close()
我希望存储变量Arpan,但我得到以下错误
回溯(最近一次呼叫): 文件“C:\Users\Home\AppData\Local\Programs\Python\Python36-32\IDLE scripts for bioinfo book\File handling\test1 reading fasta.py”,第173行,in pickle.dump(阿潘,fh) TypeError:write()参数必须是str,而不是bytes
另外,当我进入程序时
import pickle
Arpan = {"One":1,"Two":2,"Three":3}
fh = open("spdict.data","w")
pickle.dump(Arpan,fh)
fh.close()
然后,还会出现以下错误:
回溯(最近一次呼叫): 文件“C:\Users\Home\AppData\Local\Programs\Python\Python36-32\IDLE scripts for bioinfo book\File handling\test1 reading fasta.py”,第173行,in pickle.dump(阿潘,fh) TypeError:write()参数必须是str,而不是bytes
请帮忙。。我的python版本是3.6.4
编写pickle时,打开文件进行二进制写入
相关问题 更多 >
编程相关推荐