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

2013-02-24 19:27:11 +08:00
 013231
我從來沒用過, 不過今天發現文檔中說

"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不太方便, 並決定繼續不用.
3570 次点击
所在节点    Python
5 条回复
for4
2013-02-24 19:30:26 +08:00
没用过
for ... else ... 很好用
keakon
2013-02-24 19:41:38 +08:00
mikale
2013-02-24 20:59:57 +08:00
如果你用python的时候,会去用N个elif,就不会使用到这个功能

如果你使用dict来代替switch结构,就会使用到
rexren
2013-02-25 02:36:00 +08:00
SharkIng
2013-02-25 06:45:45 +08:00
没有用过这个结构

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/61228

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX