从python调用wmi时返回一个这样的列表:
[<_wmi_object: \\My_server\root\virtualization:Msvm_ComputerSystem.CreationClassName="Msvm_ComputerSystem",Name="6B76E537-049A-4AAB-8BCD-F95B2F0F8F42">]
如何检索“姓名”的值?
答案 0 :(得分:3)
[<_wmi_object: \\My_server\root\virtualization:Msvm_ComputerSystem.CreationClassName="Msvm_ComputerSystem",Name="6B76E537-049A-4AAB-8BCD-F95B2F0F8F42">]
可能是包含单个元素的列表
<_wmi_object: \\My_server\root\virtualization:Msvm_ComputerSystem.CreationClassName="Msvm_ComputerSystem",Name="6B76E537-049A-4AAB-8BCD-F95B2F0F8F42">
并且您必须阅读此对象的文档以了解如何提取名称。
答案 1 :(得分:2)
你试过了吗?
origList = [<_wmi_object: \\My_server\root\virtualization:Msvm_ComputerSystem.CreationClassName="Msvm_ComputerSystem",Name="6B76E537-049A-4AAB-8BCD-F95B2F0F8F42">, ...]
names = [getattr(rec, 'Name') for rec in origList if hasattr(rec, 'Name')]