推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
snake8090
V2EX  ›  Python

Python 小白学习读取文本时提示编码错误,搜索了很久实在没找到解决办法,求大佬指点

  •  
  •   snake8090 · May 19, 2019 · 2777 views
    This topic created in 2729 days ago, the information mentioned may be changed or developed.

    下面是错误提示

    Traceback (most recent call last): File "E:/python01/13 文件操作 /h01 读取文件.py", line 4, in <module> text = file.read() UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 34: illegal multibyte sequence</module>

    pycharm 中的文本编码也设置成 UTF-8 了,实在找不到解决办法了,求大佬指点

    hstdt
    hstdt
    May 19, 2019 via iPhone
    1
    非 python 开发,谷歌出来的 https://www.cnblogs.com/mengyu/p/6638975.html
    Sylv
    Sylv
    May 19, 2019 via iPhone
    2
    这个错误提示有很多种可能造成的,请上代码和 Python 版本。
    mainlong
    mainlong
    May 19, 2019 via Android
    3
    应该多看看错误提示,然后再去谷歌百度,基本上就了解个大概了。

    这个是 gbk 编码无法解码 0X80,在位置 34。也就是这块序列 gbk 无法解码。
    snake8090
    snake8090
    OP
    May 20, 2019
    4
    @hstdt
    @Sylv
    @mainlong
    感谢 通过指定编解码方式能读取了
    file = open("readme", encoding="utf8")
    这样
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1528 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 99ms · UTC 15:30 · PVG 23:30 · LAX 07:30 · JFK 10:30
    ♥ Do have faith in what you're doing.