[英]Can someone please tell me whats wrong with this code
response = get(url='https://benbotfn.tk/api/v1/aes')
data = response.json()
@client.command()
async def aes123(ctx):
await ctx.send(data['mainKey'])
@client.command()
async def aeskey(ctx):
embed=discord.Embed(title="aes")
embed.add_field(name='aes', value=f'{data['mainKey']} aes key')
await ctx.send(embed=embed)
I am getting this error when I run this code:运行此代码时出现此错误:
I really don't know what's wrong with this code and I'm just starting out, so sorry if this is a dumb question!我真的不知道这段代码有什么问题,我才刚刚开始,如果这是一个愚蠢的问题,很抱歉!
Inside f''
strings, if you need to access something using another string, its best to use the other quote type.在
f''
字符串中,如果您需要使用另一个字符串访问某些内容,最好使用其他引号类型。
In this case:在这种情况下:
value=f'{data['mainKey']} aes key'
is invalid syntax since you have sets of quotes within a string literal.是无效的语法,因为您在字符串文字中有多组引号。 The correct way to do it in this case is:
在这种情况下,正确的做法是:
value=f'{data["mainKey"]} aes key'
Note the use of double quotes.注意使用双引号。 Alternative options include:
替代选项包括:
value=f"{data['mainKey']} aes key"
value=f'''{data['mainKey']} aes key'''
value=f"""{data["mainKey"]} aes key"""
All of these options are valid and have their uses.所有这些选项都是有效的并且有它们的用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.