def main():
try:
exit_code = 0
# Some code that might raise an exception
except FileNotFoundError as error:
exit_code = error.errno
except (ValueError, TypeError) as error:
print(error)
finally:
sys.exit(exit_code)
if __name__ == "__main__":
main()
ValueError
和TypeError
不提供错误代码,因为pylint给我以下错误:
Instance of 'ValueError' has no 'errno' memberpylint(no-member)
Instance of 'TypeError' has no 'errno' memberpylint(no-member)
当我想退出脚本并向sys.exit()
提供错误代码时,应该为不返回错误代码的异常提供什么值?你知道吗
你们提供什么出口站由你们决定。你知道吗
如果程序成功完成,则返回0(有时称为EXIT\u SUCCESS)是被广泛接受的。失败时返回1也是很常见的(EXIT\u failure)。你知道吗
相关问题 更多 >
编程相关推荐