May 2018
Beginner
472 pages
15h 3m
English
This chapter covers
Probably the single most common thing you’ll want to do with files is open and read them.
In Python, you open and read a file by using the built-in open function and various built-in reading operations. The following short Python program reads in one line from a text file named myfile:
with open('myfile', 'r') as file_object:
line = file_object.readline()
open doesn’t read anything from the file; instead, it returns an object ...