读书人

python写utf-8文件遇到有关问题

发布时间: 2012-11-08 08:48:11 作者: rapoo

python写utf-8文件遇到问题

Python code
    import codecs        txt = u"\u5e10\u53f7\u4e0d\u5b58\u5728"    file=codecs.open("test","w","utf-8")    file.write(txt)    file.close()

这个可以正确写入
但当我的string只为ascii字符时,比如
Python code
txt = u"qwer"
时, 写入的文件仍旧为ascii格式
要怎么做才行?
谢谢

[解决办法]
不用管,因为8位的ascii编码转成utf8编码是完全一样的,等于不用转换...

读书人网 >perl python

热点推荐