Reading and Printing a File

Let’s learn how to read a file in Python.

Linux built-in word count utility

We will begin by building a simple utility called word counter. If you’re familiar with Linux you’ll know this as the wc utility. On Linux, we can type:

wc <filename>

This gets the number of words, lines, and characters in a file. The wc utility is quite advanced since it has been around for a long time. So, we’re going to build a baby version. This will hopefully be more interesting than ...