不提供异常的错误代码?

2024-04-26 03:13:14 发布

您现在位置:Python中文网/ 问答频道 /正文

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()

ValueErrorTypeError不提供错误代码,因为pylint给我以下错误:

Instance of 'ValueError' has no 'errno' memberpylint(no-member)
Instance of 'TypeError' has no 'errno' memberpylint(no-member) 

当我想退出脚本并向sys.exit()提供错误代码时,应该为不返回错误代码的异常提供什么值?你知道吗


Tags: ofinstancenomainassysexitcode
1条回答
网友
1楼 · 发布于 2024-04-26 03:13:14

你们提供什么出口站由你们决定。你知道吗

如果程序成功完成,则返回0(有时称为EXIT\u SUCCESS)是被广泛接受的。失败时返回1也是很常见的(EXIT\u failure)。你知道吗

相关问题 更多 >