.readline() returns the first line of content from an open file.
.readline() to read the first line of content from the
f = open("gullivers_travels.txt", "r", encoding='utf8')f.readline()
The example below first creates a file called
sample_text.txt and writes multiple lines of text to the file. It then calls
.readline() twice to extract the two lines of content.
- Anonymous contributorAnonymous contributor15 total contributions
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor194 total contributions