temp gbk2utf8

时间:2022-01-10 07:02:51
__author__ = 'root'
# -*- coding: utf-8 -*- ps = '/data/poitestdata/行政地名.csv'
pt = '/data/poitestdata/utf8_行政地名.csv'
perr = '/data/poitestdata/err_行政地名.csv'
f = open(ps)
f_ok = open(pt, 'w')
f_err = open(perr, 'w')
count_err = 0
count_ok = 0
while True:
line = f.readline()
if not line:
break
try:
line = line.decode('gbk')
except Exception:
f_err.write(line)
count_err += 1
continue
f_ok.write(line.encode('utf-8'))
count_ok += 1
f.close()
f_ok.close()
f_err.close()
print 'ok' + str(count_ok)
print 'err' + str(count_err)
print 'run over'