首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

请问python3.1版本下pickle类的dump函数用法

2012-02-10 
请教python3.1版本下pickle类的dump函数用法import pickleshoplistfile shoplist.datashoplist [ap

请教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")

热点排行