推荐学习书目
› 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 · Feb 24, 2013 · 4723 views
    This topic created in 4972 days ago, the information mentioned may be changed or developed.
    我從來沒用過, 不過今天發現文檔中說

    "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 replies  •  1970-01-01 08:00:00 +08:00
    for4
        1
    for4  
       Feb 24, 2013   ❤️ 1
    没用过
    for ... else ... 很好用
    keakon
        2
    keakon  
       Feb 24, 2013
    mikale
        3
    mikale  
       Feb 24, 2013   ❤️ 1
    如果你用python的时候,会去用N个elif,就不会使用到这个功能

    如果你使用dict来代替switch结构,就会使用到
    rexren
        4
    rexren  
       Feb 25, 2013
    SharkIng
        5
    SharkIng  
       Feb 25, 2013
    没有用过这个结构
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2451 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 14:54 · PVG 22:54 · LAX 07:54 · JFK 10:54
    ♥ Do have faith in what you're doing.