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

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

  •  
  •   Chyroc · 2016-08-24 23:48:19 +08:00 · 1752 次点击
    这是一个创建于 2815 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如图: code

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

    3 条回复    2016-08-25 07:50:39 +08:00
    Chyroc
        1
    Chyroc  
    OP
       2016-08-25 00:05:40 +08:00
    sleshep
        2
    sleshep  
       2016-08-25 03:11:42 +08:00
    IndexError 好些
    而且不需要 findall
    直接 match 然后 group(1)
    Chyroc
        3
    Chyroc  
    OP
       2016-08-25 07:50:39 +08:00
    @sleshep 如果网页返回 404 之类的呢,或者超时,不也会错误吗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1130 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:57 · PVG 02:57 · LAX 11:57 · JFK 14:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.