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

下载文件的时候 路径转义的问题

  •  
  •   bestehen · Jul 26, 2018 · 2187 views
    This topic created in 2918 days ago, the information mentioned may be changed or developed.

    name=data['items'][j]['name'] 这是 name 的来源 save_path = os.path.join("/home/shenjianlin/pdf_file", name)

    这是路径 ,所以在下载的时候如果 name 有'/'转义的话 就报错 路径错误

    有没有什么办法 在不改变变量 name 字符串原来的,而能够屏蔽 字符串 转义呢?因为这是变量无法用 r 屏蔽

    xpresslink
        1
    xpresslink  
       Jul 26, 2018
    用 “加号” 拼接
    或者
    save_path = os.path.join("/home/shenjianlin/pdf_file", *name.split('/'))
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3185 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 12:14 · PVG 20:14 · LAX 05:14 · JFK 08:14
    ♥ Do have faith in what you're doing.