Q
Q
quantum320432022-01-08 02:27:34
Python
quantum32043, 2022-01-08 02:27:34

How to return the result of the decorator?

The situation is this, it was necessary to return the result of the work of the following decorator from the Pyrogram module:
@app.on_message(filters.text)
def message(client, message):
msg = message.text
return msg
However, it is not possible to do this according to the principle a = message() , since I do not need to pass any arguments to this function, because they already appear, as I understand it, as a result of the work of the on_message decorator. I would really appreciate if someone could suggest what I can do about this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-08
@quantum32043

Well, for starters, what do you understand by "the result of the decorator's work"?
The result of the decorator is a function, if anything!
Those. the code

@app.on_message(filters.text)
def message(client, message):
    msg = message.text

Almost equivalent to code
decorator = app.on_message(filters.text)

def message(client, message):
    msg = message.text
# функция заменяется на результат работы декоратора - на ту же самую или другую функцию
message = decorator(message)

And what the decorator returns, as well as what else it does with the function, is its business.
Moreover, in your case, I strongly suspect that the message() function should not return anything. If you need to store the entered message, use global variables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question