Answer the question
In order to leave comments, you need to log in
How to call one line from txt?
I don't understand how to get one line from text.txt, here is the code:
def admin(chatid, userid, text):
print(2)
if isadmin(chatid, userid):
print(8)
text[5:]
if len(text.split()) > 1:
candidat = text.split()[1].strip().lower()
print(4)
if candidat[:3] == '[id' and '|' in candidat:
print(5)
nid = candidat.split('|')[0][3:]
if nid.isdigit():
print(6)
nid = int(nid)
hwid=('id'+str(nid))
print(hwid)
if hwid in open('text.txt').read():
send_message_to_chat(chatid, 'Айди уже существует в базе данных.')
return True
print('true')
f=open('text.txt', 'a')
f.write(hwid + '\n' )
send_message_to_chat(chatid, 'Айди записан в базу администраторов')
else:
send_message_to_chat(chatid, 'Вы должны быть админом')
def isadmin(chatid, userid,):
members_data = vk.messages.getConversationMembers(peer_id=2000000000 + chatid)
for i in members_data['items']:
if userid == i['member_id']:
with open('text.txt', 'r') as file:
#ids=file.readlines()
while True:
id=file.read()
print(id)
print(id)
if not id:
break
print(id)
send_message_to_chat(chatid, 'id')
if 'is_admin' in i or userid == id:
print('true')
return True
else:
print('false')
return False
Answer the question
In order to leave comments, you need to log in
I did not understand what you need, but you can read txt line by line like this:
At the output, you will have a list in id. You can check for values very simply:
>>> id = [1, 2, 3, 4, 5]
>>> if 5 in id:
... print(True)
...
True
Are you looking for the readline method ?
PS Just be aware of the presence of \n and/or \r at the end of the string it returns
PPS Although for the greatest purity, the solution to your question should look something like this .
And ideally, immediately "make friends" with sqlite.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question