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"
要怎么做才行?
谢谢
[解决办法]
不用管,因为8位的ascii编码转成utf8编码是完全一样的,等于不用转换...