您的位置:首页 > 编程语言 > Python开发

怎么解决python "Non-ASCII character"错误

2016-09-03 19:51 411 查看
#!/usr/bin/env python# This Python file uses the following encoding: utf-8'''An example of reading and writing Unicode string:'''CODEC = 'utf-8'FILE = 'unicode.txt'hello_out = u"汉字测试"bytes_out = hello_out.encode(CODEC)f = open(FILE, "w")f.write(bytes_out)f.close()f = open(FILE, "r")bytes_in = f.read()f.close()hello_in = bytes_in.decode(CODEC)print hello_in
在代码第二行添加:#coding:utf-8,解决后面出现的“汉字测试”问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐