Reputation: 443
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:

Thank you
Upvotes: 1
Views: 1500
Reputation: 865
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.
Upvotes: 3