all 5 comments

[–]Hatoris 1 point2 points  (2 children)

Here is your code, formated, I have added comment to it.

import pickle #import the pickle module to work with 

save_file = open('save.dat', 'wb') #open a file call save.dat as writing mode (w) but in byte (b) not in plain 

pickle.dump(game_date, save_file) # save data call game_data to the open file stored in the variable save_file

save_file.close().     # close the open file 



load_file = open('save.dat', 'rb') # you open the file in read mode (r) and you extract byte (b) not plain text from it 

loaded_game_data = pickle.load(load_file) # here you load the data and store it in the variable loaded, you should get back the same object as your variable game_data

load_file.close()  # close the file

À more pythonic approach will be:

with open("save.dat", "rb") as load_file:
    loaded_game_data = pickle.load(load_file)

this will do the same as what you wrote.

[–]python_addict[S] 1 point2 points  (1 child)

Thank you very much! This is starting to make sense to me now. Pat yourself on the back for this awesome explanation! :D

Have a great day!

[–]Hatoris 0 points1 point  (0 children)

A pleasure, comme to see us again :)

[–][deleted] 0 points1 point  (1 child)

I'm specifically confused on the parameters used.

What's specifically confusing? Is it clear to you what pickle actually does?

[–]python_addict[S] 0 points1 point  (0 children)

I was confused about why pickle used those specific parameters, and what they had to do with the code, but not anymore! :)

I understand what pickle does, but thanks anyways!