0

So I have a function which obtains multiple arguments from a person:

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

But how am I able to split the arguments into strings at a certain point? For instance: The user will input this: The Goblin Camp | -39,19 | 12:00 | 28/12

I need to be able to split the string at |. I tried:

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

But this still returns everything as separate. Like this:

["('The'", " 'Goblin'", " 'Camp'", " '|'", " '-39", "19'", " '|'", " '12:00'", " '|'", " '28/12')"]
2
  • 2
    ...but what is your expected output Commented Feb 28, 2017 at 15:58
  • 1
    I need something like ["('The Goblin Camp ', '-39,19')"] Commented Feb 28, 2017 at 16:02

1 Answer 1

2

You can do it like so: first join the list then split it

@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 |
Sign up to request clarification or add additional context in comments.

2 Comments

You can also write it as content = "".join(args).split('|')
Argh that worked perfectly thank you so much. ['The Goblin Camp ', ' -39,19 ', ' 12:00 ', ' 28/12']

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.