0

when searching for a user number in a text file, it looks at only the first line but never goes to the second line. It looks for the last variable in the line as that is what I am using in another file. I also get this error if line 8 is a 'while' instead of 'if'.

Thanks for any help!

count =0
user_text = str(input("Enter user num"))
found = False
def Check(user_text):
    global count, found
    #while looking for line
    fh =open("user_info.txt", "r")
    if found == False:
        print("Here")
        s =fh.readline(count)
        print(s)
        #seperate the words
        N,M,A,B=s.split("~")
        #if its found
        if user_text in B:
            found = True
            print ("line Number:", count, ":", s)
        count+=1
        print(found)
    fh.close()
    return found

found = Check(user_text)
Matthew
  • 5
  • 2

1 Answers1

1

You are using fh.readline(). This returns one line from the file, and you can use it with an optional parameter that shows the number of bytes from the line to return. If you want to iterate over the lines, use fh.readlines() (returns a list of lines).

Barish Namazov
  • 340
  • 1
  • 2
  • 13