[INPUT]
listBox = ['status: 123', 'company: test']
[期望的输出]
'zzzz' - column A already exists
'status: 123' - should be written in column B in a single cell.
'company: test' - should be written in column C in a single cell.
我试过了:
def writeToCSV():
checkpointList = ['CompanyID: test', 'StatusCode: 123']
data = [str(checkpointList).split(",")]
path = "output.csv"
with open(path, "wb") as csv_file:
writer = csv.writer(csv_file, delimiter=',')
for line in data:
writer.writerow(line)
writeToCSV()
答案 0 :(得分:0)
请尝试以下操作 - writerow
预计单list
。
import csv
def writeToCSV():
checkpointList = ['CompanyID: test', 'StatusCode: 123']
path = r"C:\out.txt"
with open(path, "wb") as csv_file:
writer = csv.writer(csv_file, delimiter=',')
writer.writerow(checkpointList)
writeToCSV()
它写道 -
CompanyID: test,StatusCode: 123