【发布时间】:2021-03-12 19:40:26
【问题描述】:
我想检查我正在开发的命令行游戏是否保存游戏。
游戏存档是单一的".txt" 文件,这段代码的工作方式是尝试打开"%appdata%\Roaming\AdventureChapt1\" 文件夹中的"name.txt" 文件,然后在Python 无法打开时查找错误消息找到文件。
我该怎么做?
print('Loading Save Data')
savecheck = open('%appdata%/Roaming/AdventureChapt1/name.txt', 'rt')
if savecheck.read() == '':
newgame() # calls the "newgame" function to bring up the New Game wizard
【问题讨论】:
标签: python error-handling file-handling