Skip to content
Sign upLog in
← Back to Community

The Pickle saver!

Profile icon
dfnk

Pickle is a module in python that can save data locally!

let's start by importing this module, import pickle:

then lest make a variable x = 10.

Now we are going to save this data first make a save.dat file then put this in the python file,

save = open('save.dat', 'wb') pickle.dump(x, save) # this will dump it into that file save.close()

this will open the save.dat file in a variable!

then if you go to your save.dat file you will see lots of gibberish, this is because it saves it in a special language!

now to open:

load = open('saver.dat', 'rb') data = pickle.load(load) x = data load.close()

this open the file and then save the data in x, and it will still be a number!

OR!

You can also do , ctrl or command + shift + s for open then terminal and put this in it pip install Saver(this is my package to help you!)

Then you can do import saver
then saver.save(x, 'save.dat') and it will save it then do saver.load('save.dat') to open!

Voters
Profile icon
MANAV0201
Profile icon
wjustin
Profile icon
dfnk
Comments
hotnewtop
Profile icon
wjustin

@dfnk
is'wb'overwriting?

Profile icon
dfnk

@wjustin
wb where?

Profile icon
wjustin

@dfnk
here:
save = open('save.dat', 'wb')
pickle.dump(x, save) # this will dump it into that file
save.close()

Profile icon
wjustin

oh and

@dfnk
, when i use pickle module my repl crashes, saying there's IDE problems

Profile icon
dfnk

@wjustin
wb means your are going to write something to the file

Profile icon
dfnk

@everyone
the saver package is currently down 😢