Python 如何从Win32_pPentity实例中提取特定属性?

Python 如何从Win32_pPentity实例中提取特定属性?,python,winapi,wmi,pywin32,wql,Python,Winapi,Wmi,Pywin32,Wql,此函数(查询)通常返回所有物理PNP设备,以下是输出示例: 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):

此函数(查询)通常返回所有物理PNP设备,以下是输出示例:

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)

问题是,如果我只想提取实例的“PNPDeviceID”,如何在python中这样做,而不改变WQL?

没关系,如图所示。WQL以列表的形式返回答案,并且有一个工厂方法“
\uuuuu getattr\uuuuuu(self,'attribute\u name'”
”,它使用特定的属性名返回数据

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";
};