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

LBYL 与 EAFP 漫谈(一点思考)

  •  
  •   scriptB0y ·
    laixintao · 2018-08-26 17:02:13 +08:00 · 2026 次点击
    这是一个创建于 2068 天前的主题,其中的信息可能已经有所发展或是发生改变。
    5 条回复    2018-08-27 10:00:03 +08:00
    whoami9894
        1
    whoami9894  
       2018-08-26 17:51:09 +08:00 via Android
    赞一个
    正则匹配中就喜欢 try + findall()[0]
    pabupa
        2
    pabupa  
       2018-08-26 18:24:20 +08:00 via Android
    我总以为异常捕获本身相对于提前检查是更耗费资源的😌
    scriptB0y
        3
    scriptB0y  
    OP
       2018-08-26 21:18:35 +08:00
    @pabupa 应该看具体情况吧,比如大多数情况异常都不发生,那么 catch 执行的次数少,catch 性能高。

    但是异常的次数很频繁,那么 catch 基本都会发生的情况下,可能 if 的性能就会高了(猜的)。
    yadam
        4
    yadam  
       2018-08-27 00:11:11 +08:00
    以前也搜了好多, 最后一句自个的话都没有, 只留下几个参考链接
    http://jialeicui.github.io/blog/EAFP_vs_LBYL.html
    scriptB0y
        5
    scriptB0y  
    OP
       2018-08-27 10:00:03 +08:00
    @yadam 资料很有用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1245 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:18 · PVG 07:18 · LAX 16:18 · JFK 19:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.