Python comes with a CSV module, and if you want to know more about it, you can refer to the official documentation
First, read operation
I do not know why, if you open the file without using the ' B ' mode, there will be interlaced, so in Windows want to normal operation of the CSV file, plus b mode. Delimiter to specify the delimiter between the various fields of reader.
def readdata (): With open ('csvfile.csv','rb' as fobj: = Csv.reader (fobj,delimiter='-'); = Next (csvfilereader); Print header for in csvfilereader: print row;
Second, write operation
Header = ["name","Sex","Age"]; Datas= [("Li Fei","male", the), ("Zhang Shan","male", -)]; With open ('Csvfile.csv','WB') asFobj:csvfilewriter= Csv.writer (fobj,delimiter='-'); Csvfilewriter.writerow (header); Csvfilewriter.writerows (datas);
These are simple CSV file read and write operations, for more detailed documentation, please refer to the official documentation
Python read/write CSV file