Answer the question
In order to leave comments, you need to log in
Removing chat id from .txt?
Hello, I ran into a problem that the bot cannot remove the telegram id from the text editor.
The write function works like this
f = open('act.txt', 'a')
f.write(str(message.from_user.id) + '\n')
with open("act.txt", "r") as f:
lines = f.readlines()
with open("act.txt", "w") as f:
for line in lines:
if line.strip("\n") != message.text:
f.write(line)
Answer the question
In order to leave comments, you need to log in
You can try like this:
import os
with open("act.txt", "r") as f:
lines = [line.replace('\n', '') for line in f.readlines() if message.from_user.id not in line] #Не добавляем выбранный пользователем id
with open("act.txt", "w") as j:
for line in lines:
if text not in line:
j.write(line)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question