开发者

From a .py file converted to an .exe (using py2exe), how do you import data from a written file?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜