【发布时间】:2020-06-29 10:19:19
【问题描述】:
我的列表列表如下:
list = [["1","this is first note.[CR][LF] This is next line","type1"], ["2","this is second note[CR][LF]. This is next line","type2"]]
我尝试将 csv 写为:
writer = open('test.csv', 'w')
csv_writer = csv.writer(writer, delimiter=";", quoting=csv.QUOTE_ALL, )
for row in rows:
if len(row) > 0:
row[1] = str(row[1]).replace("[CR]", "\r").replace("[LF]", "\n")
logging.info("writing rows into csv " + str(count))
csv_writer.writerow(row)
writer.close()
我期望得到以下结果:
|-----------|---------------------------|-------|
| id | note |type |
|-----------|---------------------------|-------|
| 1 | this is the first note.| |
| | this is next line |type1 |
| | | |
|-----------|---------------------------|-------|
但我得到了以下结果:
|--------------------|---------------------------|-------|
| id | note |type |
|--------------------|---------------------------|-------|
| 1 | this is the first note.| |
|this is next line | type1 | |
| | | |
|--------------------|---------------------------|-------|
是否可以在第一个表中按预期写入 csv?由于我是 python 和 csv 的新手,请有人帮忙吗?
【问题讨论】:
标签: python-3.x csv export-to-csv