Reading from CSV: delimiter must be a string, not unicode

后端 未结 2 1013
灰色年华
灰色年华 2020-12-19 04:01

I had a working routine (after a few helpful folks gave me some critical advice in this thread) creating model instances from a CSV file. Up to now I have been using Python

2条回答
  •  感情败类
    2020-12-19 04:38

    Happened to me when I switched the code from a file without from __future__ import unicode_literals to one that had it. (python 2.7)

    It changed the default encoding for string and messed with the existing code.

    Fixed it by changing from:

    # worked before using unicode_literals
    writer = csv.writer(csvfile, delimiter=';', quotechar='"')  
    

    to

    # worked when using unicode_literals
    writer = csv.writer(csvfile, delimiter=str(';'), quotechar=str('"'))  
    

提交回复
热议问题