Answer the question
In order to leave comments, you need to log in
How would you solve the problem of updating two databases with different encodings in Python?
I am writing a script to transfer data from an Access database with cp1251 encoding to MySQL (utf8) . I write in PyCharm using the pyodbc library. Faced a number of problems:
# -*- coding: CP1251 -*-
import pyodbc
con = pyodbc.connect("DSN=test", autocommit=True)
cur=con.cursor()
row=cur.execute("SELECT * FROM tblSiteKos WHERE ProductsId=3455").fetchone()
row=list(row)
#пример строки из базы Access
drebeden=['3455', u'kre-721', u'kre-721.jpg', u'\u041c\u044f\u0433\u043a\u043e\u0435', u'', u'', '765', 0.1, '1', '510', '25', '1', '1', u'z.html']
newlist=[]
for i in row:
if type(i)==int:newval=str(i)
if type(i)==unicode:newval=i.encode("cp1251")
else: newval=i
newlist.append(newval)
print newlist
cur.close()
con.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question