How can you save variables and load them after the program is closed? [closed]
I am creating a game and I have found out so far the most common save program, pickle, can only save/load while the program is on. The game I am making would take a long time to complete, and I don't think people would like to restart the game every time they quit. Is there a program I can import/download to save the variables elsewhere so they can be loaded again?
python pygame save load
closed as unclear what you're asking by Spencer Wieczorek, snakecharmerb, Roman Pokrovskij, Nic3500, Deadpool Nov 21 '18 at 20:26
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am creating a game and I have found out so far the most common save program, pickle, can only save/load while the program is on. The game I am making would take a long time to complete, and I don't think people would like to restart the game every time they quit. Is there a program I can import/download to save the variables elsewhere so they can be loaded again?
python pygame save load
closed as unclear what you're asking by Spencer Wieczorek, snakecharmerb, Roman Pokrovskij, Nic3500, Deadpool Nov 21 '18 at 20:26
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
pickle
– Johnny Mopp
Nov 21 '18 at 19:06
1
"can only save/load while the program is on" - This is equivalent to saying Word isn't good enough because you can't load or save a file when your computer is off. Like everything, pickle will save to a file. The file isn't going to disappear when you close the program.
– Spencer Wieczorek
Nov 21 '18 at 19:14
add a comment |
I am creating a game and I have found out so far the most common save program, pickle, can only save/load while the program is on. The game I am making would take a long time to complete, and I don't think people would like to restart the game every time they quit. Is there a program I can import/download to save the variables elsewhere so they can be loaded again?
python pygame save load
I am creating a game and I have found out so far the most common save program, pickle, can only save/load while the program is on. The game I am making would take a long time to complete, and I don't think people would like to restart the game every time they quit. Is there a program I can import/download to save the variables elsewhere so they can be loaded again?
python pygame save load
python pygame save load
edited Nov 21 '18 at 19:17


D Manokhin
599219
599219
asked Nov 21 '18 at 19:00


Budderman18Budderman18
61
61
closed as unclear what you're asking by Spencer Wieczorek, snakecharmerb, Roman Pokrovskij, Nic3500, Deadpool Nov 21 '18 at 20:26
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Spencer Wieczorek, snakecharmerb, Roman Pokrovskij, Nic3500, Deadpool Nov 21 '18 at 20:26
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
pickle
– Johnny Mopp
Nov 21 '18 at 19:06
1
"can only save/load while the program is on" - This is equivalent to saying Word isn't good enough because you can't load or save a file when your computer is off. Like everything, pickle will save to a file. The file isn't going to disappear when you close the program.
– Spencer Wieczorek
Nov 21 '18 at 19:14
add a comment |
pickle
– Johnny Mopp
Nov 21 '18 at 19:06
1
"can only save/load while the program is on" - This is equivalent to saying Word isn't good enough because you can't load or save a file when your computer is off. Like everything, pickle will save to a file. The file isn't going to disappear when you close the program.
– Spencer Wieczorek
Nov 21 '18 at 19:14
pickle
– Johnny Mopp
Nov 21 '18 at 19:06
pickle
– Johnny Mopp
Nov 21 '18 at 19:06
1
1
"can only save/load while the program is on" - This is equivalent to saying Word isn't good enough because you can't load or save a file when your computer is off. Like everything, pickle will save to a file. The file isn't going to disappear when you close the program.
– Spencer Wieczorek
Nov 21 '18 at 19:14
"can only save/load while the program is on" - This is equivalent to saying Word isn't good enough because you can't load or save a file when your computer is off. Like everything, pickle will save to a file. The file isn't going to disappear when you close the program.
– Spencer Wieczorek
Nov 21 '18 at 19:14
add a comment |
1 Answer
1
active
oldest
votes
pickle, can only save/load while the program is on
I don't know what you mean by this.
In the strictest sense, it's true -- a program can't do anything if it's not running!
But it seems like you meant that a file saved with pickle would vanish when the program quits, and that is certainly not true.
Pickle is a perfectly reasonable way to save the game progress between play sessions. Save the file before quitting, load the file on the next startup, boom you're back where you left off.
let me get a little more specific. When you setup up pickle on a program, and initiate the action of saving(temporarly in my case, pressing "s") it will save the variables requested as determined by the save code. when(in my case, the "l" key) you do the loading action, it will load the varibles right back up how you save them. It works fine. Until the program is closed. If you try to load after launching the program agin, it wont. It will throw out an error bascically saying there is nothing to load, even though you saved it earlier. Im looking for a way around this so it can load up proprly
– Budderman18
Nov 22 '18 at 15:22
Show us that code. You have a mistake in it somewhere.
– John Gordon
Nov 22 '18 at 16:16
# saving with open('savefile.dat', 'wb') as f: pickle.dump([x1], f, protocol=2) # loading with open('savefile.dat', 'rb') as f: [x1] = pickle.load(f
– Budderman18
Nov 22 '18 at 16:31
What error do you get? Also why are you putting brackets around[x1]
?
– John Gordon
Nov 22 '18 at 17:33
[x1] = pickle.load(f) ValueError: need more than 1 value to unpack
– Budderman18
Nov 22 '18 at 20:30
|
show 5 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
pickle, can only save/load while the program is on
I don't know what you mean by this.
In the strictest sense, it's true -- a program can't do anything if it's not running!
But it seems like you meant that a file saved with pickle would vanish when the program quits, and that is certainly not true.
Pickle is a perfectly reasonable way to save the game progress between play sessions. Save the file before quitting, load the file on the next startup, boom you're back where you left off.
let me get a little more specific. When you setup up pickle on a program, and initiate the action of saving(temporarly in my case, pressing "s") it will save the variables requested as determined by the save code. when(in my case, the "l" key) you do the loading action, it will load the varibles right back up how you save them. It works fine. Until the program is closed. If you try to load after launching the program agin, it wont. It will throw out an error bascically saying there is nothing to load, even though you saved it earlier. Im looking for a way around this so it can load up proprly
– Budderman18
Nov 22 '18 at 15:22
Show us that code. You have a mistake in it somewhere.
– John Gordon
Nov 22 '18 at 16:16
# saving with open('savefile.dat', 'wb') as f: pickle.dump([x1], f, protocol=2) # loading with open('savefile.dat', 'rb') as f: [x1] = pickle.load(f
– Budderman18
Nov 22 '18 at 16:31
What error do you get? Also why are you putting brackets around[x1]
?
– John Gordon
Nov 22 '18 at 17:33
[x1] = pickle.load(f) ValueError: need more than 1 value to unpack
– Budderman18
Nov 22 '18 at 20:30
|
show 5 more comments
pickle, can only save/load while the program is on
I don't know what you mean by this.
In the strictest sense, it's true -- a program can't do anything if it's not running!
But it seems like you meant that a file saved with pickle would vanish when the program quits, and that is certainly not true.
Pickle is a perfectly reasonable way to save the game progress between play sessions. Save the file before quitting, load the file on the next startup, boom you're back where you left off.
let me get a little more specific. When you setup up pickle on a program, and initiate the action of saving(temporarly in my case, pressing "s") it will save the variables requested as determined by the save code. when(in my case, the "l" key) you do the loading action, it will load the varibles right back up how you save them. It works fine. Until the program is closed. If you try to load after launching the program agin, it wont. It will throw out an error bascically saying there is nothing to load, even though you saved it earlier. Im looking for a way around this so it can load up proprly
– Budderman18
Nov 22 '18 at 15:22
Show us that code. You have a mistake in it somewhere.
– John Gordon
Nov 22 '18 at 16:16
# saving with open('savefile.dat', 'wb') as f: pickle.dump([x1], f, protocol=2) # loading with open('savefile.dat', 'rb') as f: [x1] = pickle.load(f
– Budderman18
Nov 22 '18 at 16:31
What error do you get? Also why are you putting brackets around[x1]
?
– John Gordon
Nov 22 '18 at 17:33
[x1] = pickle.load(f) ValueError: need more than 1 value to unpack
– Budderman18
Nov 22 '18 at 20:30
|
show 5 more comments
pickle, can only save/load while the program is on
I don't know what you mean by this.
In the strictest sense, it's true -- a program can't do anything if it's not running!
But it seems like you meant that a file saved with pickle would vanish when the program quits, and that is certainly not true.
Pickle is a perfectly reasonable way to save the game progress between play sessions. Save the file before quitting, load the file on the next startup, boom you're back where you left off.
pickle, can only save/load while the program is on
I don't know what you mean by this.
In the strictest sense, it's true -- a program can't do anything if it's not running!
But it seems like you meant that a file saved with pickle would vanish when the program quits, and that is certainly not true.
Pickle is a perfectly reasonable way to save the game progress between play sessions. Save the file before quitting, load the file on the next startup, boom you're back where you left off.
answered Nov 21 '18 at 19:10
John GordonJohn Gordon
9,82551729
9,82551729
let me get a little more specific. When you setup up pickle on a program, and initiate the action of saving(temporarly in my case, pressing "s") it will save the variables requested as determined by the save code. when(in my case, the "l" key) you do the loading action, it will load the varibles right back up how you save them. It works fine. Until the program is closed. If you try to load after launching the program agin, it wont. It will throw out an error bascically saying there is nothing to load, even though you saved it earlier. Im looking for a way around this so it can load up proprly
– Budderman18
Nov 22 '18 at 15:22
Show us that code. You have a mistake in it somewhere.
– John Gordon
Nov 22 '18 at 16:16
# saving with open('savefile.dat', 'wb') as f: pickle.dump([x1], f, protocol=2) # loading with open('savefile.dat', 'rb') as f: [x1] = pickle.load(f
– Budderman18
Nov 22 '18 at 16:31
What error do you get? Also why are you putting brackets around[x1]
?
– John Gordon
Nov 22 '18 at 17:33
[x1] = pickle.load(f) ValueError: need more than 1 value to unpack
– Budderman18
Nov 22 '18 at 20:30
|
show 5 more comments
let me get a little more specific. When you setup up pickle on a program, and initiate the action of saving(temporarly in my case, pressing "s") it will save the variables requested as determined by the save code. when(in my case, the "l" key) you do the loading action, it will load the varibles right back up how you save them. It works fine. Until the program is closed. If you try to load after launching the program agin, it wont. It will throw out an error bascically saying there is nothing to load, even though you saved it earlier. Im looking for a way around this so it can load up proprly
– Budderman18
Nov 22 '18 at 15:22
Show us that code. You have a mistake in it somewhere.
– John Gordon
Nov 22 '18 at 16:16
# saving with open('savefile.dat', 'wb') as f: pickle.dump([x1], f, protocol=2) # loading with open('savefile.dat', 'rb') as f: [x1] = pickle.load(f
– Budderman18
Nov 22 '18 at 16:31
What error do you get? Also why are you putting brackets around[x1]
?
– John Gordon
Nov 22 '18 at 17:33
[x1] = pickle.load(f) ValueError: need more than 1 value to unpack
– Budderman18
Nov 22 '18 at 20:30
let me get a little more specific. When you setup up pickle on a program, and initiate the action of saving(temporarly in my case, pressing "s") it will save the variables requested as determined by the save code. when(in my case, the "l" key) you do the loading action, it will load the varibles right back up how you save them. It works fine. Until the program is closed. If you try to load after launching the program agin, it wont. It will throw out an error bascically saying there is nothing to load, even though you saved it earlier. Im looking for a way around this so it can load up proprly
– Budderman18
Nov 22 '18 at 15:22
let me get a little more specific. When you setup up pickle on a program, and initiate the action of saving(temporarly in my case, pressing "s") it will save the variables requested as determined by the save code. when(in my case, the "l" key) you do the loading action, it will load the varibles right back up how you save them. It works fine. Until the program is closed. If you try to load after launching the program agin, it wont. It will throw out an error bascically saying there is nothing to load, even though you saved it earlier. Im looking for a way around this so it can load up proprly
– Budderman18
Nov 22 '18 at 15:22
Show us that code. You have a mistake in it somewhere.
– John Gordon
Nov 22 '18 at 16:16
Show us that code. You have a mistake in it somewhere.
– John Gordon
Nov 22 '18 at 16:16
# saving with open('savefile.dat', 'wb') as f: pickle.dump([x1], f, protocol=2) # loading with open('savefile.dat', 'rb') as f: [x1] = pickle.load(f
– Budderman18
Nov 22 '18 at 16:31
# saving with open('savefile.dat', 'wb') as f: pickle.dump([x1], f, protocol=2) # loading with open('savefile.dat', 'rb') as f: [x1] = pickle.load(f
– Budderman18
Nov 22 '18 at 16:31
What error do you get? Also why are you putting brackets around
[x1]
?– John Gordon
Nov 22 '18 at 17:33
What error do you get? Also why are you putting brackets around
[x1]
?– John Gordon
Nov 22 '18 at 17:33
[x1] = pickle.load(f) ValueError: need more than 1 value to unpack
– Budderman18
Nov 22 '18 at 20:30
[x1] = pickle.load(f) ValueError: need more than 1 value to unpack
– Budderman18
Nov 22 '18 at 20:30
|
show 5 more comments
pickle
– Johnny Mopp
Nov 21 '18 at 19:06
1
"can only save/load while the program is on" - This is equivalent to saying Word isn't good enough because you can't load or save a file when your computer is off. Like everything, pickle will save to a file. The file isn't going to disappear when you close the program.
– Spencer Wieczorek
Nov 21 '18 at 19:14