From the course: Using Python for Automation (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

How to read files

How to read files

- [Instructor] File IO is a fundamental of programing. Because it lets scripts not only create, but also interact with external files. Today we'll be working with a short text file I've created, which I've named inputfile.txt. And you can find this in the exercise files for this course. It just contains some arbitrary data, but we can imagine it as a public survey where we tested individuals on whether they could pass a test. The columns represent their name, age, and whether or not they passed the test. P denotes pass and F denotes fail. Now that you're armed with some context, once your file is downloaded, move it into your working directory and let's get started. The first goal is to read the inputfile.txt. So reading files in Python is actually very simple and requires no outside libraries. To read a file all we need to do is use the built-in function, open, and pass in two parameters: the file name and how we'd like to interact with that file. Let me show…

Contents