How does python handle csv files
This article mainly introduces the relevant knowledge of "how python deals with csv files". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope that this article "how python deals with csv files" can help you solve the problem.
The specific steps are as follows:
1. First, open python and create a new python project
After the 2.python project is created, import the csv library in the project using the import method
Import csv
After the 3.csv library is imported, use the open () function to open the csv file and create the file object
With open (infile, "r", newline='') as incsv, open (outfile, "w", newline='') as outcsv:
After the 4.csv file is opened, use the reader () and writer () functions to get the file object
Freader = csv.reader (incsv, delimiter= ",")
Fwriter = csv.writer (outcsv, delimiter= ",")
5. Finally, after you get the file object, you can write data to the file using the writerow () method.
Fwriter.writerow ('data to be written')
This is the end of the introduction to "how python handles csv files". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.