Python 异常和错误处理时,try...except
、if...else...
哪个更好一些,为什么?
The point is that using try/except statements is in many cases much more natural (more “Pythonic”) than if/else, and you should get into the habit of using them where you can.
这个是《Beginning Python From Novice to Professional, 2nd Edition》里的原话,但 StackOverflow 里又有
Why is “except: pass” a bad programming practice?
我就疑惑了……到底哪个好一些?还是说有更好的方法?
千巷猫影
月关宝盒
相关分类