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

如何解析非命令行输入的命令式文本?

  •  
  •   Candyhorse · 2013-03-21 23:15:47 +08:00 · 3005 次点击
    这是一个创建于 4043 天前的主题,其中的信息可能已经有所发展或是发生改变。
    类似这样的命令:

    post search v2ex
    post search -a Livid
    ……

    不是从命令行输入,而是用户从网页端输入

    根据不同的命令,匹配不同的处理逻辑

    除了手工正则匹配外,有没有能够更方便地处理类似情况的模块?

    谢谢:)
    5 条回复    1970-01-01 08:00:00 +08:00
    YUCOAT
        1
    YUCOAT  
       2013-03-22 11:30:38 +08:00 via Android
    不太明白你的意思
    undeflife
        2
    undeflife  
       2013-03-22 11:44:28 +08:00
    OptionParser
    hit9
        3
    hit9  
       2013-03-22 11:54:21 +08:00   ❤️ 1
    docopt 不错的。
    Candyhorse
        4
    Candyhorse  
    OP
       2013-03-22 13:46:38 +08:00
    @hit9

    very nice ~

    不知道 Python 自带的 argparser 能不能完成类似的任务?
    huangzxx
        5
    huangzxx  
       2013-03-22 20:22:51 +08:00
    argparser 是推荐用的,optparse 已经 deprecated
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4176 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:22 · PVG 13:22 · LAX 22:22 · JFK 01:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.