Writing and reading files in Python
The title of this section may sound strange as you are probably used to seeing it written as reading and writing, but in this section, you will write data to files first, then read it. By writing it, you will understand the structure of the data and you will know what it is you are trying to read.
To write data, you will use a library named faker
. faker
allows you to easily create fake data for common fields. You can generate an address by simply calling address()
, or a female name using name_female()
. This will simplify the creation of fake data while at the same time making it more realistic.
To install faker
, you can use pip
:
pip3 install faker
With faker
now installed, you are ready to start writing files. The next section will start with CSV files.
Writing and reading CSVs
The most common file type you will encounter is Comma-Separated Values (CSV). A CSV is a file made up of fields separated by commas. Because commas are...