* ******** This document is intended for beginners to avoid detours, click ************************
1. Remember to set the encoding method at the beginning of the. py file. The format is as follows.
# Coding = UTF-8
** Remember Chinese Characters
2. Do not overwrite the append file.
Csvfile = file (filepath, 'a + B ') writer = csv. writer (csvfile) writer. writerow (["name", "Age", "gender"])
The append parameter is: +,
Note: writer. the parameter in the writerow () method is of the list type. To write 'hello' in column A1. writerow (['hello']), otherwise 'hello' will be regarded as a list and written into five columns.
When writing a csvfile, add 'B' to the created csvfile, that is, csv.writer(open('test.csv ', 'wb'). Otherwise, there will be a line break. The explanation found on the internet is: When python writes files normally, '\ n' is added to the end of each line by default, that is, 0x0D, while 0x0D0A is added to the end of the writerow command, therefore, for windows systems, there are two lines, while the 'B' parameter is used to write files in binary format. By default, 0x0D is not added.
3. global Variables
The global variables are defined. If you need to reference them in the method, the following is true:
Global variable name