import
csv
fieldnames
=
[
‘Column1‘
,
‘Column2‘
,
‘Column3‘
,
‘Column4‘
]
rows
=
[{
‘Column1‘
:
‘0‘
,
‘Column2‘
:
‘1‘
,
‘Column3‘
:
‘2‘
,
‘Column4‘
:
‘3‘
},
{
‘Column1‘
:
‘0‘
,
‘Column2‘
:
‘1‘
,
‘Column3‘
:
‘2‘
,
‘Column4‘
:
‘3‘
},
{
‘Column1‘
:
‘0‘
,
‘Column2‘
:
‘1‘
,
‘Column3‘
:
‘2‘
,
‘Column4‘
:
‘3‘
},
{
‘Column1‘
:
‘0‘
,
‘Column2‘
:
‘1‘
,
‘Column3‘
:
‘2‘
,
‘Column4‘
:
‘3‘
},
{
‘Column1‘
:
‘0‘
,
‘Column2‘
:
‘1‘
,
‘Column3‘
:
‘2‘
,
‘Column4‘
:
‘3‘
}]
dict_writer
=
csv.DictWriter(
file
(
‘your.csv‘
,
‘wb‘
), fieldnames
=
fieldnames)
dict_writer.writeheader()
# 这里写header
dict_writer.writerows(rows)
# rows就是表单需要写到csv文件的数据
时间: 2024-10-08 06:39:27