推荐学习书目
› 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 · 5823 views
    This topic created in 3848 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
        1
    vanxining  
       Mar 13, 2016
    看 os.walk() 是怎样处理的,对症下药。
    Sylv
        2
    Sylv  
       Mar 13, 2016 via iPhone   ❤️ 1
    Shell 命令里路径两头加引号。
    例子:
    os.system("ls '{}'".format(project_dir))
    xieguobihaha
        4
    xieguobihaha  
    OP
       Mar 13, 2016
    @Sylv 感谢!
    xieguobihaha
        5
    xieguobihaha  
    OP
       Mar 13, 2016
    @jimmyye 感谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1439 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:33 · PVG 00:33 · LAX 09:33 · JFK 12:33
    ♥ Do have faith in what you're doing.