gpt4 book ai didi

python - Python 中 Win32_ComputerSystem 的 __name__ 属性?

转载 作者:行者123 更新时间:2023-11-30 23:43:22 24 4
gpt4 key购买 nike

我正在尝试获取 WMI win32 类的名称。但没有为其定义 __name__ 属性。

>> import wmi
>> machine = wmi.WMI()
>> machine.Win32_ComputerSystem.__name__

我收到以下错误:

Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
machine.Win32_ComputerSystem.__name__
File "C:\Python27\lib\site-packages\wmi.py", line 796, in __getattr__
return _wmi_object.__getattr__ (self, attribute)
File "C:\Python27\lib\site-packages\wmi.py", line 561, in __getattr__
return getattr (self.ole_object, attribute)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 457, in __getattr__
raise AttributeError(attr)
AttributeError: __name__

我认为 __name__ 属性是 defined for all Python functions ,所以我不知道问题出在哪里。这个函数怎么可能没有这个属性呢?

好吧,我认为它是一个方法的原因是因为 machine.Win32_ComputerSystem() 被定义了,但我想这还不足以成为一个方法。我意识到这不是一种方法。

但是,这不起作用:

>> machine.Win32_ComputerSystem.__class__.__name__
'_wmi_class'

我希望它返回“Win32_ComputerSystem”。我怎样才能做到这一点?

最佳答案

据我所知,查看 the documentation (具体来说,基于 this snippet ),wmi.Win32_ComputerSystem 是一个类,而不是一个方法。如果你想知道它的名字,你可以尝试:

machine.Win32_ComputerSystem.__class__.__name__

关于python - Python 中 Win32_ComputerSystem 的 __name__ 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10821749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com