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

求教, python shell 路径包含空格的问题

  •  
  •   xieguobihaha · Mar 13, 2016 · 5920 views
    This topic created in 3896 days ago, the information mentioned may be changed or developed.
    问题是这样的,我定义了一个全局的 project_dir = "xxx/a b/xxx",使用 os.walk 没有问题,执行 shell 命令就会出错,查了下是说 shell 需要对空格转义,那么换成 project_dir = "xxx/a\ b/xxx",这下 shell 可以了, python 的 os.walk 又出问题了,求教大家是如何处理这种冲突的?难道要定义两个变量分别处理。。。
    5 replies  •  2016-03-13 13:10:14 +08:00
    vanxining
    vanxining
    Mar 13, 2016
    1
    看 os.walk() 是怎样处理的,对症下药。
    Sylv
    Sylv
    Mar 13, 2016 via iPhone❤️1
    2
    Shell 命令里路径两头加引号。
    例子:
    os.system("ls '{}'".format(project_dir))
    xieguobihaha
    xieguobihaha
    OP
    Mar 13, 2016
    4
    @Sylv 感谢!
    xieguobihaha
    xieguobihaha
    OP
    Mar 13, 2016
    5
    @jimmyye 感谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2618 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:38 · PVG 18:38 · LAX 02:38 · JFK 05:38
    ♥ Do have faith in what you're doing.