Why do these python snippets contradict each other? [duplicate]

  python, readfile, split

I have two python snippets:

file = open("text.txt", "r")
leng = len(file.read().splitlines())
file.close()

and

file = open("text.txt", "r")
print(file.readline())
file.close()

They work separately, but when I put on before the other on the same piece of code, the second snippet returns nothing, even though there is still a piece of text on the selected line of the text file.

Source: Python Questions

LEAVE A COMMENT