我从source.sql读(sql脚本)文件python编码问题?
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 ?
只是一个想法:你检查你的表定义吗? – jensgram 2009-12-02 08:16:47
我更新了我的queston.Thanks征求意见。 – kn3l 2009-12-02 08:40:19
是的,因为我用法语 – kn3l 2009-12-02 08:47:49