简体   繁体   English

python dmidecode模块中的方法/属性是什么?

[英]What are methods/attributes in dmidecode module in python?

I need to know about my system's hardware as described in BIOS and use it in a python program. 我需要了解BIOS中描述的系统硬件,并在python程序中使用它。 So I came to know about this python module dmidecode and I installed it in my machine. 所以我开始了解这个python模块dmidecode,并将其安装在我的机器上。 But I cannot understand the methods in it. 但是我无法理解其中的方法。 For instance : 例如 :

>>> dir(dmidecode)
['TYPE', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_get_output', '_parse_handle_section', '_show', 'parse_dmi', 'profile']

Now, when I am trying to access the individual methods, it is giving the following errors: 现在,当我尝试访问各个方法时,出现以下错误:

>>> dmidecode._parse_handle_section()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: _parse_handle_section() takes exactly 1 argument (0 given)

>>> dmidecode._show()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: _show() takes exactly 1 argument (0 given)

>>> dmidecode.parse_dmi()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: parse_dmi() takes exactly 1 argument (0 given)

Now, the real problem is that, I cannot find any good tutorial to study and understand the usage of these methods. 现在,真正的问题是,我找不到任何好的教程来研究和理解这些方法的用法。

So any help or links will be greatly appreciated. 因此,任何帮助或链接将不胜感激。

Here are some alternatives: 以下是一些替代方案:

  • You can use pydoc <module> to access the module's documentation from the system shell, and pydoc <module>.<method> to access a specific method docstring. 您可以使用pydoc <module>从系统外壳访问模块的文档,并使用pydoc <module>.<method>访问特定的方法docstring。

  • You can use help(<module>) to access the same documentation from the Python shell, and help(<module>.<method>) for a method docstring. 您可以使用help(<module>)从Python Shell访问相同的文档,并使用help(<module>.<method>)获取方法docstring。

  • You can use %pinfo <module> and %pinfo2 <module> to access the docstrings and read the source code from the IPython shell, which is an alternative to the normal shell you are using. 您可以使用%pinfo <module>%pinfo2 <module>来访问文档字符串并从IPython Shell中读取源代码,这是您正在使用的普通Shell的替代方法。 This also works for methods. 这也适用于方法。

If there is no documentation or docstrings whatsoever, then your only option is to read the code with IPython and %pinfo2 . 如果没有任何文档或文档字符串,那么您唯一的选择是使用IPython和%pinfo2读取代码。

And a word of advice: in Python, a method which has a _ prepended usually is meant to be private, while methods starting and ending with __ are called "magic" and are "even more private", so to speak. 一个建议:在Python中, 通常_开头的方法是私有的,而以__开头和结尾的方法称为“魔术”,并且可以说是“更私有的”。

You can always access everything, but from the looks of the dir call, you should concentrate on the parse_dmi and profile functions. 您始终可以访问所有内容,但是从dir调用的外观来看,您应该专注于parse_dmiprofile函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM