Writing and reading existing txt. file

To read a specific line from a text file, you can use the readlines() method to get a list of all the lines in the file, and then access the specific line by its index.

with open('file.txt', 'r') as file:
    lines = file.readlines()
    third_line = lines[2] #reads the 3rd line in the doc
    print(third_line)