请教python3.1版本下pickle类的dump函数用法
import pickle
shoplistfile = 'shoplist.data'
shoplist = ['apple', 'mango', 'carrot']
f = open(shoplistfile,'w')
pickle.dump(shoplist, f)
f.close()
结果却报如下错误,看不明白,还请各位大侠帮忙看下~
>>>
Traceback (most recent call last):
File "F:\Python Source\AddrList.py", line 7, in <module>
pickle.dump(shoplist, f)
File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
TypeError: must be str, not bytes
>>>
[解决办法]
python 3可能改动啥的了吧,查查手册先,估计必要2进制模式开档open(shoplistfile, "wb")