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

python 代码片段异常设置的是否合理?

  •  
  •   Chyroc · Aug 24, 2016 · 2207 views
    This topic created in 3620 days ago, the information mentioned may be changed or developed.

    如图: code

    想要实现一个模拟登陆,先获取下登陆数据。 担心失败什么的或者上面两个参数取[0]超出范围异常,所以为了判断这种情况,可以抛出一个异常吗? 这样的话,最后执行的时候判断就可以了?并且怎么判断呢? py 大神求指教~

    3 replies    2016-08-25 07:50:39 +08:00
    Chyroc
        1
    Chyroc  
    OP
       Aug 25, 2016
    sleshep
        2
    sleshep  
       Aug 25, 2016
    IndexError 好些
    而且不需要 findall
    直接 match 然后 group(1)
    Chyroc
        3
    Chyroc  
    OP
       Aug 25, 2016
    @sleshep 如果网页返回 404 之类的呢,或者超时,不也会错误吗
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1146 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 18:02 · PVG 02:02 · LAX 11:02 · JFK 14:02
    ♥ Do have faith in what you're doing.