G
G
Gospodin_Kiroshi2021-10-12 21:53:39
Python
Gospodin_Kiroshi, 2021-10-12 21:53:39

How to make the bot ignore punctuation?

Let's say there is text
If msg.text.lower() == 'How to eat an apple?':
await msg.reply('Hands')

How to tell the bot that "?" sign and generally other symbols do not always need to be taken into account? Do not write the same command a second time, only without a question mark.

Please post the full result!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
o5a, 2021-10-13
@Gospodin_Kiroshi

You can remove all specified characters from the list through str.translate

text = 'Как съесть яблоко?'
text = str.translate(text, str.maketrans('', '', '.,?:-;/\\'))

R
Ronald McDonald, 2021-10-12
@Zoominger

replace ('all punctuation', '')

N
Nikolay Savelyev, 2021-10-13
@AgentSmith

"execution cannot be pardoned"
well, now let's encourage the lack of punctuation, I think that in the future you will encounter big problems, but IMHO, if you decide to remove all punctuation marks, then just do replace () then you will be left with bare text without punctuation marks, the approach is controversial but has the right to life, I think, again, IMHO, in general, it’s up to you to decide how to be better, but you can ask how many such examples you have, that is, how many such cases appear in dialogues, it’s one thing when there are 5-10 percent of them and another thing when there are 90 of them, but anyway, I would not encourage this IMHO

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question