python - 如何在一行中使用相同的参数两次?
问题描述
我的不和谐机器人有以下代码:
@bot.command(brief="Za map napiš Rod a druh a vyskočí ti mapa výskytu!")
async def map(ctx, *args):
if not args:
await ctx.channel.send("Nenapsal jsi Rod/ Rod a druh! \nVysvětlivka:")
await ctx.channel.send(
"https://cdn.discordapp.com/attachments/661985293834125342/808308254081417227/acz_map_command.png"
)
else:
await ctx.channel.send('Mapa výskytu: *{}*'.format(
' '.join(args).capitalize()))
await ctx.channel.send(
'https://antmap.coc.tools/images/{}.png '.format(
'.'.join(args).capitalize()))
await ctx.channel.send('AntWiki: *{}*'.format(
' '.join(args).capitalize()))
await ctx.channel.send(
'https://antwiki.org/wiki/{}'.format(
'_'.join(args).capitalize()))
问题在这里:
await ctx.channel.send(
'https://antmap.coc.tools/images/{}.png '.format(
'.'.join(args).capitalize()))
Bot 在您使用命令后发送此信息:https://antmap.coc.tools/images/Argument1.Argument2.png
但现在我需要更改它,所以它发送 https://antmap.coc.tools/images/Argument1/Argument1.Argument2.png
它应该看起来像这样:
'https://antmap.coc.tools/images/{}/{}.png'
或像这样:
'https://antmap.coc.tools/images/{}.png'.format(
'/','.'.join(args).capitalize()
或类似的东西?
我已经搜索了一些答案,但我还无法弄清楚。
解决方案
尝试:
'https://antmap.coc.tools/images/{}/{}.{}.png'.format(arg1,arg1,arg2)
请参阅:https ://docs.python.org/3/tutorial/inputoutput.html#the-string-format-method
推荐阅读
- html - 为什么零元素宽度会导致其父级滚动,我该如何防止这种情况发生?
- c++ - C++ 编译器如何在 C++17 中实现折叠表达式?
- java - Minecraft 函数文件结构
- r - 如何使用 ggplot2 在轴上使用科学记数法固定小数位数?
- java - 如何使用 java 类选择并写入外部 Windows 控制台
- node.js - npm install bootstrap@4.0.0 命令给出 ENETUNREACH 错误
- python - 如何编码分类预测值?
- java - 根据字符串的不同模式拆分字符串
- json - 我有嵌套的列表对象,称为 JSON 中的剧集,那么如何根据 id 父对象而不是位置对象获取剧集列表?
- python - 数据框中的字符串编辑不使用 .replace 代码生效