The practice of reading and writing csv files by python
Csv introduction
What is csv? Everyone may have heard of it, but I guess few people can give a more comprehensive explanation, so I will make a fool of myself. Csv what I understand is a file that stores data with commas as splits (or tabs).
Rules of csv
1 begins with no space, with a behavior unit.
2 column names may or may not be included, and column names are on the first line of the file.
3 a row of data does not span rows and has no blank lines.
(4) use a half-corner comma (that is,) as a delimiter, and a blank column should also express its existence.
If there are half-width quotation marks (that is, "), replace them with half-width double quotation marks ("), that is, enclose the field value in half-width quotes (that is,").
(6) the operation rules of quotation marks and commas are reciprocal when reading and writing files.
7 Internal code format is unlimited, can be ASCII, Unicode or other.
8 Special characters are not supported
Python csv
Csv module is built into python, which can be used directly by import csv.
The common methods are as follows:
Writer 、 DictWriter 、 reader 、 DictReader
There should be no need for me to explain. If you don't know, check the meaning of English for yourself. Those with dict are read and written through a dictionary.
Code actual combat
For how to obtain the source code, please watch the video.