如何从Win32_PnPEntity实例中提取特定属性? [英] How to extract a particular attribute from instance of Win32_PnPEntity?
本文介绍了如何从Win32_PnPEntity实例中提取特定属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def getPnpDeviceInfo():
c = wmi.WMI()
wql = "SELECT * FROM Win32_PnPEntity WHERE Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\%'"
print ("All physical PNP devices")
for J in c.query(wql):
print(J)
此函数(查询)通常返回所有物理PNP设备,这是一个输出示例:
This function (the query) typically returns all physical PNP devices, here is an output sample :
instance of Win32_PnPEntity
{
Caption = "ACPI Lid";
ClassGuid = "{4d36e97d-e325-11ce-bfc1-08002be10318}";
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_PnPEntity";
Description = "ACPI Lid";
DeviceID = "ACPI\\PNP0C0D\\2&DABA3FF&3";
HardwareID = {"ACPI\\PNP0C0D", "*PNP0C0D"};
Manufacturer = "(Standard system devices)";
Name = "ACPI Lid";
PNPDeviceID = "ACPI\\PNP0C0D\\2&DABA3FF&3";
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "SUSDUTTA-LAP";
};
问题是,如果我只想提取实例的"PNPDeviceID",如何在python中执行此操作而不更改WQL?
Question is, if I want to extract just the "PNPDeviceID" of the instance, how to do so in python, without changing the WQL?
推荐答案
没关系,请参见__getattr__(self,'attribute_name'_)",该方法使用特定的属性名称返回了数据.
Never mind, figured in the WMI python doc. The WQL returns the answer as a list, and there is a factory method "__getattr__(self,'attribute_name'_)
" which returned the data using specific attribute name.
这篇关于如何从Win32_PnPEntity实例中提取特定属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文