繁体   English   中英

如何在Python3中获取/分割多个字符串输入

[英]How do you obtain/split multiple string inputs in Python3

所以我有一个函数,可以从一个人那里获取多个参数:

@bot.command(name='koth')
async def koth_announcer(*args):

但是,如何在特定点将参数拆分为字符串? 例如:用户将输入以下内容: The Goblin Camp | -39,19 | 12:00 | 28/12 The Goblin Camp | -39,19 | 12:00 | 28/12

我需要能够在|处分割字符串 我试过了:

args = str(args).split('|')

但这仍然将所有内容都单独返回。 像这样:

["('The'", " 'Goblin'", " 'Camp'", " '|'", " '-39", "19'", " '|'", " '12:00'", " '|'", " '28/12')"]

您可以这样操作:首先加入列表,然后将其拆分

@bot.command(name='koth')
async def koth_announcer(*args):
    msg = "".join(args) #joins the list of words first
    content = msg.split('|') #split the words at |

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM