【发布时间】:2022-06-13 18:43:46
【问题描述】:
我在制作 csv 文件时遇到此错误。
Traceback(最近一次调用最后一次): 文件“tester.python3”,第 5 行,在 标题["ID","重量","类型","价格"] NameError: name 'headers' 没有定义
我的代码:
import csv
headers["ID","Weight","Type","Price"]
products=[["1","10","XBL-3","30,00"],["2","15","MM-2","10,00"],
["3","7","Ll-0","5,00"]]
with open("products.csv","w")as prod:
product = csv.writer(prod)
product.writerow(headers)
product.writerows(products)
【问题讨论】:
-
您的意思是:
headers = ["ID","Weight","Type","Price"]?
标签: python python-3.x