推荐学习书目
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
css3
V2EX  ›  Python

python3 在 windows 读取路径多了一个\u202a 是咋回事😥

  •  
  •   css3 · Feb 19, 2019 · 4700 views
    This topic created in 2664 days ago, the information mentioned may be changed or developed.

    如题,读取文件,读到一半,报错了,发现打印的文件路径+文件名中多了个'\u202ad',骑怪的很,怎么解决啊?重命名也行😱

    文件在这里:

    D:\bulkControl\20181129\009.jpg'
    

    读取出来长这样,怎么回事😡

    OSError: [Errno 22] Invalid argument: '\u202aD:\\bulkControl\\20181129\\009.jpg'
    

    encode 也不管用

    UnicodeEncodeError: 'gb2312' codec can't encode character '\u202a' in position 0: illegal multibyte sequence
    
    
    10 replies    2019-02-20 11:45:06 +08:00
    loveour
        1
    loveour  
       Feb 19, 2019
    搜 u202a,你会有发现的。
    css3
        2
    css3  
    OP
       Feb 19, 2019
    @loveour 网上说手输路径,手动输入也是一样的错
    andylsr
        3
    andylsr  
       Feb 19, 2019 via Android
    py 版本多少~我 3.6.7 和 3.6.8 没问题
    python35
        4
    python35  
       Feb 19, 2019
    应该是你直接从文件的属性界面直接复制的路径吧
    把这个这个所在的字符串整个删掉(包括引号),再手动敲一遍就好了
    css3
        5
    css3  
    OP
       Feb 19, 2019
    @andylsr 3.7.2
    css3
        6
    css3  
    OP
       Feb 19, 2019
    @python35 关键是只有部分文件这样,大部分正常的,手敲也是一样的
    LuJason
        7
    LuJason  
       Feb 20, 2019
    换个编辑器试试,比如 vs、vim
    allen2000
        8
    allen2000  
       Feb 20, 2019
    Use Raw String, r'D:\bulkControl\20181129\009.jpg'
    css3
        9
    css3  
    OP
       Feb 20, 2019
    解决了,是因为有些文件名中有繁体中文,导致的编码有误
    Itoktsnhc
        10
    Itoktsnhc  
       Feb 20, 2019
    之前遇到过的就是在文件属性->安全选项卡的路径复制出来就会有这个 \u202a
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2837 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 02:45 · PVG 10:45 · LAX 19:45 · JFK 22:45
    ♥ Do have faith in what you're doing.