L
L
lolchik2020-06-25 13:32:42
Python
lolchik, 2020-06-25 13:32:42

How to save with pickle?

there is a stats dictionary and a save.txt file. You need to save and load this file through pickle. I'm probably stupid, but I've been sitting with this garbage for the second evening and this is what happened

stats = {1 : 2,2 : 3}
save = open("save.txt","w")
with open(save,"w") as save:
  pickle.dump(stats,save)

with this code
throws TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-06-25
@lo1chik

import pickle
stats = {1 : 2,2 : 3}
with open("save","wb") as save:
  pickle.dump(stats,save)

pickle module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question