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

你們寫Python代碼時是否使用`try...except...else...`結構?

  •  
  •   013231 · 2013-02-24 19:27:11 +08:00 · 3564 次点击
    这是一个创建于 4075 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我從來沒用過, 不過今天發現文檔中說

    "The use of the else clause is better than adding additional code to the try clause because it avoids accidentally catching an exception that wasn’t raised by the code being protected by the try ... except statement."

    http://docs.python.org/2/tutorial/errors.html

    但我仍然覺得多出個else clause不太方便, 並決定繼續不用.
    5 条回复    1970-01-01 08:00:00 +08:00
    for4
        1
    for4  
       2013-02-24 19:30:26 +08:00   ❤️ 1
    没用过
    for ... else ... 很好用
    keakon
        2
    keakon  
       2013-02-24 19:41:38 +08:00
    mikale
        3
    mikale  
       2013-02-24 20:59:57 +08:00   ❤️ 1
    如果你用python的时候,会去用N个elif,就不会使用到这个功能

    如果你使用dict来代替switch结构,就会使用到
    rexren
        4
    rexren  
       2013-02-25 02:36:00 +08:00
    SharkIng
        5
    SharkIng  
       2013-02-25 06:45:45 +08:00
    没有用过这个结构
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4102 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:17 · PVG 18:17 · LAX 03:17 · JFK 06:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.