如何从 Win32_PnPEntity 的实例中提取特定属性?

How to extract a particular attribute from instance of 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)

此函数(查询)通常 returns 所有物理 PNP 设备,这里是一个输出示例:

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",如何在不更改 WQL 的情况下在 python 中提取?

没关系,想通了WMI python doc。 WQL returns 答案是一个列表,还有一个工厂方法“__getattr__(self,'attribute_name'_)”,它使用特定的属性名称返回数据。