美文网首页
Python3报错:UnicodeDecodeError: 'a

Python3报错:UnicodeDecodeError: 'a

作者: 满船清梦压星河ya_ | 来源:发表于2018-12-21 10:07 被阅读0次

    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文件都去修改一遍,不知道还没有没其他好的解决方法。特此记录

    相关文章

      网友评论

          本文标题:Python3报错:UnicodeDecodeError: 'a

          本文链接:https://www.haomeiwen.com/subject/fjapkqtx.html