V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
ccaa5j
V2EX  ›  Python

求个大佬,帮我看看这个问题

  •  
  •   ccaa5j · 172 天前 · 742 次点击
    这是一个创建于 172 天前的主题,其中的信息可能已经有所发展或是发生改变。

    C:\Users\Administrator\Desktop\测试>python 1.py Traceback (most recent call last): File "1.py", line 119, in <module> urls = ['{}'.format(str(i)) for i in open(inFile)] File "1.py", line 119, in <listcomp> urls = ['{}'.format(str(i)) for i in open(inFile)] UnicodeDecodeError: 'gbk' codec can't decode byte 0x9b in position 3070: illegal multibyte sequence

    有一个脚本,之前一直都可以用的,但是现在不能用了,会报错, 保存文本的编码都是有设置 utf-8 的,我不懂 python

    7 条回复    2023-11-08 13:42:51 +08:00
    phoulx
        1
    phoulx  
       172 天前
    报错说了用 gbk 无法 decode ,open(inFile)改成 open(inFile, encoding='utf-8')试下。
    这种基础问题直接问 GPT 就可以;或者把代码和文件都贴出来,不然大家都没什么兴致回复。
    nzbstn
        2
    nzbstn  
       172 天前 via Android
    基础问题,善用百度等搜索引擎,chatGPT 虽然也是个出路但还是得有一点代码基础
    maocat
        3
    maocat  
       172 天前 via iPhone
    经典问题,以前是好的,怎么现在坏了
    ccaa5j
        4
    ccaa5j  
    OP
       172 天前
    @maocat 哈哈,非常真实
    ccaa5j
        5
    ccaa5j  
    OP
       172 天前
    @phoulx 那我在折腾一下
    ccaa5j
        6
    ccaa5j  
    OP
       172 天前
    @nzbstn 关键就是我没有基础,崩溃了
    nzbstn
        7
    nzbstn  
       171 天前
    没办法, 多写多练就好了, 都是这么过来的(至少我自己是这样的), 遇到的问题多了, 后面自然就好了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2899 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 07:53 · PVG 15:53 · LAX 00:53 · JFK 03:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.