The practice of operating csv Files with python3.x
Description
Python3.x integrates the operation of csv files and can be directly introduced into the package, but python2.x needs to be installed separately.
Actual combat
1. Read csv file
# introduce package import csv# to open the file csvfile = open ('xiaoqiang.csv',newline='') # get the object csvReader = csv.reader (csvfile) # read the contents and print for content in csvReader: print (content) # off. Some friends often forget that some people in the group have encountered this problem today, csvfile.close ()
2. Write to csv file
# introduce the package import csv# to open the file csvfile = open ('xiaoqiang.csv', 'wicked journal new lineages') # get the object writer = csv.writer (csvfile) # write a row of data writer.writerow (('name', 'URL')) # define the content rows= to write multiple lines of data [('Xiaoqiang's blog', 'https://blog.51cto.com/xqtesting'), (' Xiaoqiang's video') 'http://edu.51cto.com/lecturer/4626073.html')]# writes multiline writer.writerows (rows) # turns off csvfile.close ()