把两种不一样编码方式的文件整合放到一个utf-8的文件中

#-*- coding:utf-8 -*-
'''
Created on 2012-8-22

@author : alex
'''
try: 
    JAP=open("F:\\pythonwork\\jap.txt","r") 
    CHN=open("F:\\pythonwork\\chn.txt","r") 
    UTF=open("F:\\pythonwork\\utf.txt","w") 

#    jap_text=JAP.readline() 
#    chn_text=CHN.readline() 
    for j in JAP.readlines():
        #先decode成UTF-16,再encode成UTF-8 
        jap_text_utf8=j.decode("SHIFT_JIS").encode("UTF-8")
        UTF.write(jap_text_utf8) 
        #不转成utf-8也能够 
    for c in CHN.readlines():
        chn_text_utf8=c.decode("GB2312").encode("UTF-8") 
        #编码方式大小写都行utf-8也同样 
        UTF.write(chn_text_utf8) 
    UTF.close() 
except IOError,e: 
    print "open file error",e 
print 'write is ok'
相关文章
相关标签/搜索