V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
goruningwall
V2EX  ›  Python

Python 命令行参数包围文本只能用双引号?

  •  
  •   goruningwall · Jan 4, 2018 · 3821 views
    This topic created in 3042 days ago, the information mentioned may be changed or developed.

    比如
    test.py:
    import sys
    args = sys.argv
    print(args)
    >>python test.py hello 'world hhh' "gg mm"
    ['test.py', 'hello', "'world", "hhh'", 'gg mm']

    5 replies    2018-01-05 13:25:02 +08:00
    jmc891205
        1
    jmc891205  
       Jan 4, 2018
    我试了 Python2.7.2, Python3.3.4, Python3.6.0 都不能重现你这个问题
    goruningwall
        2
    goruningwall  
    OP
       Jan 4, 2018
    @jmc891205 我发现问题的根源,估计因为我的 cmd 装了 clink,在 powershell 测试就正常
    akmonde
        3
    akmonde  
       Jan 4, 2018
    @goruningwall powershell 命令行里面再搞 py 的命令行,这么屌..
    goruningwall
        4
    goruningwall  
    OP
       Jan 5, 2018
    @akmonde 我不懂,这会出现什么问题吗?
    Arnie97
        5
    Arnie97  
       Jan 5, 2018 via Android
    命令行参数的解析是 Shell 完成的,跟 Python 没关系,只跟你用的是 cmd 还是 bash 有关,你用其他语言来测试 argv 结果也是一样的。

    然后 cmd 只支持双引号。结贴
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2897 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 06:28 · PVG 14:28 · LAX 23:28 · JFK 02:28
    ♥ Do have faith in what you're doing.