Answer the question
In order to leave comments, you need to log in
How to save information about entered messages in different files?
I'm writing a bot to find timetables. To send a request, you need the names of cities. I save them in separate files, however, the last city is written to both files. In words, I understand well why this happens, but I don’t know how to fix everything and write each city to a separate file, due to my almost zero knowledge of python
@bot.message_handler(content_types=['text'])
def handle_text(message):
potp = message.text
fmas = open('otprav.txt', 'w')
fmas.write(potp)
from constants import libArray
fmas = open('otprav.txt', 'r')
findIt = fmas.read() # Значение, которое ищется
if findIt == 'Создать расписание':
bot.send_message(message.from_user.id, 'Выберите город отправления')
if findIt in libArray:
fromcity = libArray[findIt]
print(fromcity)
if bot.send_message(message.from_user.id, 'Отлично! Теперь выберите город прибытия.'):
ppr = message.text
tmas = open('prib.txt', 'w')
tmas.write(ppr)
from constants import libArray
fmas = open('prib.txt', 'r')
findt = fmas.read() # Значение, которое ищется
if findt in libArray:
tocity = libArray[findIt]
print(tocity)
if potp not in libArray and not potp == 'Создать расписание':
bot.send_message(message.from_user.id, 'К сожалению, этот город еще не обслуживается')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question