So, I am trying to read only one line from a text file that I opened, but I keep getting this error: AttributeError: 'str' object has no attribute 'readlines'.
Here is the code. I am not very comfortable in python. What should I do?
file = askopenfilename(filetypes = (("Text File", ".txt"), ("All Files", ".")),
title = "Please, choose a file")
if file is None:
return
content = file.readlines()
print(content[74])
askopenfilename()only returns a filename. Did you meancontent = open(file).readlines()?readline()is not a string method which is becausefileis a string, not an open file.