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

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

  •  
  •   goruningwall · 2018-01-04 15:32:40 +08:00 · 3143 次点击
    这是一个创建于 2275 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    然后 cmd 只支持双引号。结贴
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3171 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:25 · PVG 20:25 · LAX 05:25 · JFK 08:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.