SyntaxError:无效的语法与with打开



我想写一个json文件,但这一行给了我语法错误

with open("tries.json", "w") as f:

SyntaxError: invalid SyntaxError;是精确是精确误差

相关的全部代码
with open("tries.json", "r") as f:
    data = json.load(f)
    f.close()
if data["code"]["ended"] == True:
    await ctx.send("This event has already ended")
else:
    if data["code"][str(ctx.author.id)]["tries"] > 0:
        if data["code"][str(ctx.author.id)["correct"] == False:
            with open("tries.json", "w") as f:
                del data["code"][str(ctx.author.id)]
                update = {
                    ctx.author.id: {"tries": 1, "correct": True}
                }
                data["code"].update(update)
                json.dump(data, f)
                f.close()
            await ctx.send("**Now you need to use Caesar's Cipher. Use ~answer [code] to take the prize. Every capital letter is required. You have only 1 attempt for this command. Take your time! Hint: the answer contains real words**")
        else:
            await ctx.send("**You've already answered correctly**")

我找不到任何有用的东西,所以我希望我能从这里得到帮助,谢谢!

if data["code"][str(ctx.author.id)["correct"] == False:

您缺少一个]

应该是

if data["code"][str(ctx.author.id)]["correct"] == False:

相关内容

最新更新