错误的Python模块应该抛出适当的错误

时间:2017-11-14 09:58:37

标签: python error-handling runtime psutil

我正在使用Python模块psutil,我在代码中使用了psutil虚拟模块。例如,

Python 2.7.3 (default, Oct 26 2016, 21:01:49)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.sensor()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sensor'

我希望输出如下所示

Python 2.7.3 (default, Oct 26 2016, 21:01:49)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.sensor()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sensor'
RuntimeError: Unsupported function Sensor()   >>> looking for this output

我想在psutil模块中更改哪些更改才能获得该输出?

0 个答案:

没有答案