Reading files
While databases such as MySQL and Postgres are popular and widely used in many web applications, a large amount of data is still stored and exchanged using text file formats. Popular formats such as comma-separated values (CSV), JavaScript Object Notation (JSON), and plain text are used to store information such as weather data, traffic data, and sensor readings. In the following exercise, you will learn how to read text from a file using Python.
Exercise 59 – reading a text file using Python
In this exercise, you will be downloading a sample data file from the internet and reading data as the output. Follow these steps:
- Open a new Jupyter notebook.
- Now, copy the entire text from https://packt.live/2MIHzhO, save it to a local folder as
pg37431.txt
, and remember where it is located. - Upload the file to your Jupyter notebook by clicking on the Upload button in the top-right corner. Select the
pg37431.txt
file from your local folder, and then...