V
V
Vlad Tanashchuk2020-06-12 23:37:52
Python
Vlad Tanashchuk, 2020-06-12 23:37:52

How to get multiple lines from a user's post?

How can I get and split the lines of a user's message into two different variables?
Now, to get one variable from the user's message, I use this script:

if msg.startswith('!сообщение'):
   message = msg.lstrip('!сообщение').strip()
   print(message)

And the user's message looks like this:
!message text
Print displays "text".
I need the message format to look like this:
!message "1 variable" "2 variable"
In simple terms - you need to make two different variables from one message.
Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-12
@Xaeruz

You can use regular expressions

impore re
re.findall(r'(".+?")', message)

Or split by quotes, but then extra quotes will remain, which can then be removed.
message.split('" "')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question