With regard to the question of python storage and fetch storage, TypeError: and UnicodeDecodeError:

system: win10
IDLE:spyder3.

script: (about saving and fetching storage)

-sharp!/usr/bin/python
-sharp Filename: pickling.py
import cPickle as p
-sharpimport pickle as p
shoplistfile = "shoplist.data"
-sharp the name of the file where we will store the object
shoplist = ["apple", "mango", "carrot"]
-sharp Write to the file
f = file(shoplistfile, "w")
p.dump(shoplist, f) -sharp dump the object to a file
f.close()
del shoplist -sharp remove the shoplist
-sharp Read back from the storage
f = file(shoplistfile)
storedlist = p.load(f)
print storedlist

run TypeError: write () argument must be str, not bytes
(then I found out that f = file (shoplistfile,"w") needs to use "wb", in a two-tier way)

error occurs when running UnicodeDecodeError: "gbk" codec can"t decode byte 0x80 in position 0: illegal multibyte sequence
(prompt storedlist = p.load (f), there is a problem with the sequence here)

there are some reasons that I can"t figure out. I don"t know where it is. How can I solve it?

there is also a question about the software spyder. After running this script once, the script code in spyder disappears for the attribute color, all white, and can not be used to run the function, screenshot.


Mar.30,2022

binary mode is also required to read files

f = file(shoplistfile, 'rb')
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b5cb-4eef0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b5cb-4eef0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?