Joshua Sullivan Joshua Sullivan -4 years ago 146
Python Question

How do you obtain/split multiple string inputs in Python3

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

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')"]

Answer Source

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

async def koth_announcer(*args):
    msg = "".join(args) #joins the list of words first
    content = msg.split('|') #split the words at |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download