import json
def save(directory: str,data: str):
try:
with open(directory) as file:#Note that the format of your file should be .json and it can also be .txt
json.dump(data, file)
except FileNotFoundError:
return "no such directory or file found"
def show(directory: str):
try:
with open(directory) as file: # Note that the format of your file should be .json
json.load(file)
except FileNotFoundError:
return "no such directory or file found"
请参考以下帖子:How do you append to a file in Python?
如果您自己实现了Snake and ladder游戏,只需将本文中显示的代码部分添加到脚本中即可。另一方面,如果您没有访问游戏代码的权限,则可以在游戏运行时跟踪进程并运行跟踪脚本。 (Constantly monitor a program/process using Python)
干杯
使用json包执行此操作:
相关问题 更多 >
编程相关推荐