A
A
Alex_8882019-06-24 18:59:54
Python
Alex_888, 2019-06-24 18:59:54

Python. Pass variable to another function?

The code :

def func1(message):
    markup = telebot.types.ReplyKeyboardMarkup(True)
    markup.row('hello too')
    send = bot.send_message(admin_id,'hello',reply_markup=markup)
    bot.register_next_step_handler(message, func3)
def func3(message):
    if message.text == 'hello too':
        bot/send_message(chat_id=message.from_user.id, message_id=send.message_id, text = 'hail')
        bot.delete_message(chat_id=admin_id, message_id=send.message_id)

You need to pass the 'send' variable from func1 to func3
You can write it to .txt

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tsarevfs, 2019-06-24
@Alex_888

This is probably what you want:

bot.register_next_step_handler(message, lambda msg: func3(send, msg))
...
def func3(send, message):

Instead of func3, an unnamed (lambda) function will be called, which will already call func3 with an additional parameter.

Y
Yura Khlyan, 2019-06-24
@MAGistr_MTM

1. Return what you need from the first function
2. Write the result (what returns) of the 1st function to a variable
3. Pass the variable from p2 (the result of the first function) to the second as an argument
4. ?????
5. PROFIT!!!!111

I
ID-B, 2021-11-07
@ID-B

How to pass variables from function to function in aiogram

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question