系統:win10
IDLE:spyder3.
腳本:(關于儲存和取儲存)
#!/usr/bin/python
# Filename: pickling.py
import cPickle 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 = file(shoplistfile, 'w')
p.dump(shoplist, f) # dump the object to a file
f.close()
del shoplist # remove the shoplist
# Read back from the storage
f = file(shoplistfile)
storedlist = p.load(f)
print storedlist
運作出現錯誤 TypeError: write() argument must be str, not bytes
(然後我百度查到說, f = file(shoplistfile, 'w')需要用'wb',以二級制的方式)
再次運作出現錯誤 UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 0: illegal multibyte sequence
(提示storedlist = p.load(f),在這邊的序列有問題)
有些摸不到頭緒,不知道是哪裡的原因,請問可以如何解決?
另外還有一個關于軟體spyder的問題,運作這個腳本一次之後,spyder裡面的腳本代碼對于屬性顔色消失了,全是白色,而且也無法是用運作功能,截圖示意。
運作後