您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

用Python将字符串列表写入Excel CSV文件

用Python将字符串列表写入Excel CSV文件

方法以iterable作为参数。您的结果集必须是列表(列)的列表(行)。csv.writerwriterow

csvwriter.writerow(row)

参数写入编写者的文件对象,并根据当前方言格式化。

执行以下任一操作:

import csv
RESULTS = [
    ['apple','cherry','orange','pineapple','strawBerry']
]
with open('output.csv','wb') as result_file:
    wr = csv.writer(result_file, dialect='excel')
    wr.writerows(RESULTS)

要么:

import csv
RESULT = ['apple','cherry','orange','pineapple','strawBerry']
with open('output.csv','wb') as result_file:
    wr = csv.writer(result_file, dialect='excel')
    wr.writerow(RESULT)
python 2022/1/1 18:27:18 有193人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶