Reading a UTF8 CSV file with Python

后端 未结 9 1537
青春惊慌失措
青春惊慌失措 2020-11-22 12:20

I am trying to read a CSV file with accented characters with Python (only French and/or Spanish characters). Based on the Python 2.5 documentation for the csvreader (http://

9条回答
  •  抹茶落季
    2020-11-22 12:57

    Using codecs.open as Alex Martelli suggested proved to be useful to me.

    import codecs
    
    delimiter = ';'
    reader = codecs.open("your_filename.csv", 'r', encoding='utf-8')
    for line in reader:
        row = line.split(delimiter)
        # do something with your row ...
    

提交回复
热议问题