1

I would like to import my csv file into Postgresql using Python. The import works well. However, when I display the imported data, I find a special symbol on the first line and first column. I tried to solve the problem by adding the encoding in my python code but nothing has to do. Here is my code:

import sys
import os
import csv
import io
f = io.open(r'C:\\list.csv', mode='r', encoding='utf-8')
curs.copy_from(f, 'list', sep=';')
conn.commit()

Here is the symbol or special character:



enter image description here

Thank you

ChumiestBucket
  • 868
  • 4
  • 22
  • 51
Bak
  • 411
  • 1
  • 5
  • 19

1 Answers1

3

You are picking up the Byte order mark.

In order to have the io module expect and strip off the BOM try changing your encoding to utf-8-sig:

f = io.open(r'C:\\list.csv', mode='r', encoding='utf-8-sig')

More info here.

Simon
  • 855
  • 9
  • 24
  • It works perfectly. Thank you for your help and for the link to Byte order mark. – Bak Jul 05 '18 at 19:19