如何在Python中编写一个空的缩进块? [英] How to write an empty indentation block in Python?
本文介绍了如何在Python中编写一个空的缩进块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行时不断告诉我:
期望缩进的块
expected an indented block
但是我不想在我的除外块中什么也不写,我只希望它捕获并吞下异常.
But I don't want write nothing inside my except block, I just want it to catch and swallow the exception.
推荐答案
只需编写
pass
与
try:
# Do something illegal.
...
except:
# Pretend nothing happened.
pass
@swillden提出了一个很好的观点,即,通常这是一个糟糕的主意.您至少应该说
@swillden brings up a good point, viz., this is a terrible idea in general. You should, at the least, say
except TypeError, DivideByZeroError:
或您要处理的任何类型的错误.否则,您可以掩盖更大的问题.
or whatever kinds of errors you want to handle. Otherwise you can mask bigger problems.
这篇关于如何在Python中编写一个空的缩进块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文