需要解析,参数1必须具有“write”方法。把字典编成一个cs

2024-10-05 13:21:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我似乎不能让我的代码工作,它一直给我相同的'参数1必须有'写'方法

import csv
tank1 = [{'tank':1, 'product':['condenstate'], 'temp':12,'ullage':21000, 'level':70000}]
tank2 = [{'tank':2, 'product':['condenstate'], 'temp':12,'ullage':21000, 'level':70000}]
key1 = tank1,tank2[0].keys()
with open('motherwell.csv','w',newline='') as output_file:
    writer = csv.writer 

    writer = csv.writer(output_file, key1)
    writer = csv.writer(key1)

Tags: csv代码output参数productleveltempfile
1条回答
网友
1楼 · 发布于 2024-10-05 13:21:29

不确定你想达到什么目标,但你可能只需要:

with open('motherwell.csv','w', newline='') as output_file:
    writer = csv.writer(output_file)
    writer.writerow(tank1)
    writer.writerow(tank2)

注意:对于Python3,对于Python2,您需要以二进制文件的形式打开文件(wb)。在

相关问题 更多 >

    热门问题