Я читаю из файла source.sql (sql script)
INSERT INTO `Tbl_abc` VALUES (1111, 2222, 'CLEMENT', 'taya', 'MME', 'Gérant', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 4688, 0, NULL, NULL, 'MAILLOT 01/02/09', 'MAILLOT 01/04/09', NULL, NULL);
И напиши на dest.sql С моим списком, сформированным
Я встретил проблему с кодировкой, например:
Gérant= G\xc3\xa9rant
ЧТО Я ПЫТАЮСЬ
def DataMigration(dest, source, tbl_name, return_data=True):
'''
'''
data = []
for ln in codecs.open(source, 'r', "utf-8").xreadlines():
replace1 = ln.replace("INSERT INTO `"+tbl_name+"` VALUES (", "")
replace2 = replace1.replace(");", "")
list_replace = replace2.split(',')
s = list_replace
data.append(list_replace)
if return_data == True:
ouputdata = [d for d in data if d[1] == ' 0' and d[6]==' 0']
return ouputdata
if return_data == False:
return data
Я печатаю
печать DataMigration ('dest.sql', '.source.sql', 'Tbl_abc', False)
ВЫХОД
[['1111', ' 2222', " 'CLEMENT'", " 'taya'", " 'MME'", " 'G\xc3\xa9rant'", ' NULL', ' NULL', ' NULL', ' NULL', ' NULL', ' NULL', ' NULL', ' 4688', ' 0', ' NULL', ' NULL', " 'MAILLOT 01/04/09'", " 'MAILLOT 01/04/09'", ' NULL', ' NULL']]
But My Ouput file still has the problem.Any Could help me ?