daiyue
daiyue

Reputation: 7448

TypeError: "delimiter" must be a 1-character string

I am trying to read a csv file using Python 3.7 csv.reader on windows using jupyter notebook;

class my_dialect(csv.Dialect):
    lineterminator = '\n'
    deliminter = ';'
    quotechar = '"'
    quoting = csv.QUOTE_MINIMAL

reader = csv.reader(f, dialect=my_dialect)

I got the following errors:

TypeError                                 Traceback (most recent call last)
<ipython-input-70-ddd19e28755c> in <module>
      5     quoting = csv.QUOTE_MINIMAL
      6 
----> 7 reader = csv.reader(f, dialect=my_dialect)

TypeError: "delimiter" must be a 1-character string

I am wondering how to fix it.

Upvotes: 1

Views: 3310

Answers (1)

dizzyf
dizzyf

Reputation: 3593

Looks like a potential typo there: deliminter = ';'

should be "delimiter" to pick it up correctly.

Reference docs: https://docs.python.org/3/library/csv.html#csv.Dialect.delimiter

Upvotes: 3

Related Questions