I need to take 2 user inputs and turn them into a list and further into variables.
I have a starting command which I can ignore by splitting the message with
user_input = str(message.content).split('!command ')
but the outcome is ['', 'input1, input2']
and I need the whole thing to be seperated like ['', 'input1', 'input2']
so I can take the inputs with indexing and further work with them.
CodePudding user response:
If you want to assign them to separate variables in one line:
input1, input2 = str(message.content).split('!command ')[1].split(', ')
CodePudding user response:
Try this ( it's a bit dirty but it works):
data = '!command input1, input2'
inputs = data.split('!command ')[-1].split(', ') #to get inputs
But why there is a comma between input 1 and 2 ? Is it better if the command is :
'!command input1 input2'
You can split by space and then get inputs.
CodePudding user response:
Try:
user_input = str(message.content).split('!command ')
user_input = [y for x in user_input for y in x.split(', ')]