我有一个作为 .py 文件分发的简单库。如果库是从 Python 2 而不是 Python 3 调用的,我想抛出一个异常:
def _check_version():
if sys.version_info < (3,):
raise _____Exception('This library depends on Python 3 strings. Please ensure you are using Python 3 instead of Python 2')
我应该引发什么内置异常? (我如何填写上面的空白?)我能在 builtin Exceptions 中找到最接近的异常。是 NotImplementedError。 DeprecationWarning 感觉很接近,但在这种情况下异常(exception)更合适。
最佳答案
我会使用 RuntimeError
为了这;没有更具体的异常(exception)。
关于python - 如果您的库与错误的 Python 版本一起使用,应该引发什么适当的内置异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46164094/