0
i am making a program q reads a specific line from a.txt file so that I can then separate the line and get the information. i did this function to know on which line the CPF that was typed is located
def get_line(word):
    with open('alunos.txt') as alunos:
        for l_num, l in enumerate(alunos, 1): 
            if word in l: 
                return l_num
        return False 
the file "students.txt" has information like this:
nome do aluno 1,CPF,Semestre de ingresso
nome do aluno 2,CPF,Semestre de ingresso
...
here’s another part of the code:
cpf = input("\nDigite o CPF do aluno: ")
with open('alunos.txt') as alunos:
    for line in alunos:
        if cpf in line:
            posicao = int(get_line(cpf))
            
            inf = alunos.readlines()[posicao]
            #text = inf.split(',')  
            print(inf)
            break
    else:
        print("CPF não cadastrado\n")
the problem I get is this: when I type Cpf q is on the first line of the file, it returns the third line. and if I type any other Cpf just gives error... if I give a print on the variable "position" it returns the number of the right line, but when I read using readlines() this problem happens