python 操作csv

python 操作csv

 

写csv

import csv

with open('path/to/file.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    writer.writerow(['Name', 'Age', 'Gender'])
    writer.writerow(['Alice', '25', 'Female'])
    writer.writerow(['Bob', '30', 'Male'])

  

读csv

import csv

with open('path/to/file.csv', newline='') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in reader:
        print(', '.join(row))

  

 

 

 

##################

posted @ 2023-04-14 08:49  西北逍遥  阅读(21)  评论(0编辑  收藏  举报