【问题标题】:getting an header error csv file in python在python中获取标题错误csv文件
【发布时间】: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


猜你喜欢
  • 2019-04-29
  • 2018-09-14
  • 1970-01-01
  • 2021-08-09
  • 2016-11-22
  • 2020-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多