怎么解决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,解决后面出现的“汉字测试”问题
相关文章推荐
- ubuntu下怎么解决python "Non-ASCII character"错误
- 怎么解决windows下使用eclipse和python编译时候 "Non-ASCII character"错误问题
- 怎么解决python "Non-ASCII character"错误
- 怎么解决python "Non-ASCII character"错误?
- 怎么解决python "Non-ASCII character"错误
- python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法
- 解决python "Non-ASCII character"错误
- 解决python "Non-ASCII character"错误
- 解决python "Non-ASCII character"错误
- python "Non-ASCII character"错误
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- 使用Openjdk 编译Android4.4时遇到"error: unmappable character for encoding ASCII"错误的解决方法
- python 遇到 syntaxerror: non-ascii character '/xd6' in file 我 教你解决 (python问题)
- 关于Python报错:SyntaxError: Non-ASCII character '\xe5'的解决方法
- python 处理中文时出现的错误'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)" 解决方法
- python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法
- Python错误: SyntaxError: Non-ASCII character eclipse pydev 下