temp gbk2utf8

__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'

 

posted on 2013-12-03 09:55  雨渐渐  阅读(176)  评论(0编辑  收藏  举报

导航