как обратить функцию в переменную? чтобы можно было после к ней обращаться и выдергивать file_id
def save_file(message):
try:
chat_id = message.chat.id
file_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'C:/tmp/' + message.document.file_name
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "сохраню это")
except Exception as e:
bot.reply_to(message, e)
Ответы (1 шт):
Автор решения: Albert
→ Ссылка
Вы можете вернуть из функции file_id:
def save_file(message):
try:
chat_id = message.chat.id
file_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'C:/tmp/' + message.document.file_name
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "сохраню это")
except Exception as e:
bot.reply_to(message, e)
return message.document.file_id
Тогда в основном коде вы сможете присвоить переменной file_id и одновременно выполнить функцию:
new_file = save_file(message)