python中的异常。给定定义,如何在代码内部调用它?

时间:2018-12-20 13:56:43

标签: python

在库中定义了以下异常:

exception paramiko.ssh_exception.AuthenticationException
Exception raised when authentication failed for some reason. It may be possible to retry with different credentials. (Other classes specify more specific reasons.)

在我的代码中,如果我写:

except AuthenticationException:

我得到一个错误。

如果我写:

except paramiko.AuthenticationException:

有效。

为什么不呢?

except paramiko.ssh_exception.AuthenticationException:

如何知道给定的定义要写什么?

paramiko库显然是导入的:

import paramiko

1 个答案:

答案 0 :(得分:2)

我猜paramiko软件包中有以下__init__.py

from .ssh_exception import *

然后,如果您import paramiko,您将拥有paramiko下的所有内容,而没有其他子分支

相关问题