wally=pickle.load(open("The Wall.txt","rb"))
usernamey=pickle.load(open("username1.txt","rb"))
wu=("\n", wally, "\n", usernamey, "\n")
apost=input("Enter your post below: \n")
pwickle=pickle.dump(wu, apost, open("The Wall.txt","wb"))
Don't know why this isn't working, comes up with error message:
pwickle=pickle.dump(wu, apost, open("The Wall.txt","wb"))
TypeError: an integer is required
As unutbu pointed out, the third argument is the protocol. You should group all the objects you want to pickle in a tuple like this:
pwickle=pickle.dump((wu, apost), open("The Wall.txt","wb"))
If you need to pickle a larger amount of data, you could use the shelve
module that operates like a dictionary.
By the way, the files pickle creates are binary (or at least not human readable, depends on the protocol), so I wouldn't name them .txt
. .db
, .pickle
or something like that would be better.
第三个参数指定协议,协议应为整数,0、1或2。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.