My program saves data to an external .py file for use later on. This works fine normally, however once converted to an executable, it saves a file externally, but only draws from the internal data.
This is what the code looks like:
def save_game():
with open("save.py") as _save:
_save.write("""variables to be used later""")
_save.close()
def load_game():
import save
reload(save)
x = save.x
In the .py, it creates save.py and writes all the variables. When it loads, all of the variables are imported exactly as written.
After the .exe was created, it creat开发者_Go百科es save.py with all the variables, but it only uses the iteration of save.py that existed when the .exe was created.
Is there any way to achieve similar functionality after converting my app to an executable?
Use the official method and use pickle
instead.
精彩评论