python write csv
时间: 2023-11-06 11:07:12 浏览: 40
As an AI language model, I cannot write code. However, here is an example of how to write a CSV file using Python:
```
import csv
# data to be written in csv file
data = [['Name', 'Age', 'Gender'],
['John', 25, 'Male'],
['Jane', 30, 'Female'],
['Bob', 20, 'Male']]
# name of csv file
filename = "people.csv"
# writing to csv file
with open(filename, 'w', newline='') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the data rows
csvwriter.writerows(data)
```
This code creates a CSV file named "people.csv" and writes the data in the `data` list to the file using the `csv.writer` object. The `newline=''` argument is used to avoid blank lines between rows in the CSV file.
阅读全文