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
bestehen
V2EX  ›  Python

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

  •  
  •   bestehen · 2018-07-26 11:09:08 +08:00 · 1529 次点击
    这是一个创建于 2072 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    xpresslink
        1
    xpresslink  
       2018-07-26 11:29:01 +08:00
    用 “加号” 拼接
    或者
    save_path = os.path.join("/home/shenjianlin/pdf_file", *name.split('/'))
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2770 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:24 · PVG 08:24 · LAX 17:24 · JFK 20:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.