- 论坛徽章:
- 0
|
windows 环境下报错:- import sys
- reload(sys)
- sys.setdefaultencoding( 'utf8')
- #--*- coding:gbk --*--
- import pickle as p
- #import pickle as p
- shoplistfile = 'shoplist.data'
- # the name of the file where we will store the object
- shoplist = ['apple', 'mango', 'carrot']
- # Write to the file
- f = open(shoplistfile, 'wb')
- p.dump(shoplist, f) # dump the object to a file
- f.close()
- del shoplist # remove the shoplist
- # Read back from the storage
- f = open(shoplistfile)
- storedlist = p.load(f)
- print ('the following text comes from data e:\lib\shoplist.data')
- print (storedlist)
复制代码- Traceback (most recent call last):
- File "E:/lib/pickling.py", line 3, in <module>
- sys.setdefaultencoding( 'utf8')
- AttributeError: 'module' object has no attribute 'setdefaultencoding'
复制代码 |
|