utf8编码

2015-09-21 0 868
utf8编码
def main():
    fin = open('utf8.txt', 'r', encoding='utf_8')
    fout = open('utf8.html', 'w')    
    outbytes = bytearray()    
    for line in fin:
        for c in line:
            if ord(c) > 127:
                outbytes += bytes('&#{:04d}'.format(ord(c)), encoding='utf_8')
            else: outbytes.append(ord(c))
    outstr = str(outbytes, encoding='utf_8')    
    print(outstr, file=fout)
    print(outstr) #&#1641(&#0865&#3663&#0815&#0865&#3663)&#1782
    print("Done.")       

if __name__ == "__main__": main()

遇见资源网 python utf8编码 http://www.ox520.com/15781.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务