如何在DictReader中使用quotechar

时间:2018-06-19 15:10:16

标签: python python-3.x

我在代码中遇到以下错误。我究竟做错了什么。谢谢。

TypeError: 'quotchar' is an invalid keyword argument for this function

这是我的方法:

def read_csv_fieldnames(filename, separator, quote):
    """
    Inputs:
      filename  - name of CSV file
      separator - character that separates fields
      quote     - character used to optionally quote fields
    Ouput:
      A list of strings corresponding to the field names in
      the given CSV file.
    """
    with open(filename, "rt", newline='') as csvfile:
        dict_reader = csv.DictReader(csvfile,
                                     skipinitialspace=True,
                                     delimiter=separator,
                                     quotchar=quote)


        return dict_reader.fieldnames;

这就是我的使用方式。

print(read_csv_fieldnames("isp_csv_files/table1.csv", ",", "''"))

1 个答案:

答案 0 :(得分:0)

一个简单的错字:quotchar应该是quotechar。错误消息几乎可以告诉您。