Python3报错:UnicodeDecodeError: 'a

2018-12-21  本文已影响0人  满船清梦压星河ya_

Python在进行编码方式之间的转换时,会将 unicode 作为“中间编码”,但 unicode 最大只有 128 那么长, unicode 由于超出了其范围,就报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)

        txt11 = '''备注信息
1、Python3报错怎么办
2、IPython3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办
3、Python3报错怎么办Python3报错怎么办Python3报错怎么办
4、IPython3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办
5、Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办'''

解决方法:
在太长的字符串前加u,如下:

        txt11 = u'''备注信息
1、Python3报错怎么办
2、IPython3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办
3、Python3报错怎么办Python3报错怎么办Python3报错怎么办
4、IPython3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办
5、Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办Python3报错怎么办'''

经过测试,该方法可以解决报错的问题,但需要每个.py文件都去修改一遍,不知道还没有没其他好的解决方法。特此记录

上一篇下一篇

猜你喜欢

热点阅读