The problem is with you did not read the file. First we have to open the desired file to be red and go through the lines (reading). Then we can find the length of the particular lines. Here I have written a simple snippet. Please check whether this works for you.
def txtFile_reader(txtFile_location):
length_list = []
with open(txtFile_location, 'r') as txt_file:
for i, line in enumerate(txt_file.readlines(), 1):
length_list.append((len(line.strip()), i))
return max(length_list)[1]
if __name__ == '__main__':
main()
This returns which line contains the longest string, if you need to see the string count as wellm then return max(length_list)
. It will return a tupple containing first element denoting the string count followed by the line number. (xxx, xx)