How to Read a File

Let's learn how to read a file in python

Python has a builtin function called open that we can use to open a file for reading. For our examples in this course, we will use a text file name “test.txt” with the following contents (don’t worry, we’ve already worked with Educative to have these files uploaded to your execution directory):

This is a test file
line 2
line 3
this line intentionally left blank

Get hands-on with 1200+ tech skills courses.