January 2019
Intermediate to advanced
390 pages
9h 16m
English
Python has built-in functions that read and write into TXT files. The complete functionality is provided using four sets of functions: open(), read(), write(), and close(). As the names suggest, they are used to open a file, read from a file, write into a file, and finally close it. If you are dealing with string data (text), this is the best choice. In this section, we will use Shakespeare plays in TXT form; the file can be downloaded from the MIT site: https://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt.
We define the following variables to access the data:
data_folder = '../../data/Shakespeare'data_file = 'alllines.txt'
The first step here is to open the file:
f = open(data_file)
Next, ...
Read now
Unlock full access