python类如何用不同的名称初始化?
昨天我不得不在python项目中使用WMI。我找到了python库。 这个库有很好的文档记录,有很多工作示例。e、 g:python类如何用不同的名称初始化?,python,wmi,Python,Wmi,昨天我不得不在python项目中使用WMI。我找到了python库。 这个库有很好的文档记录,有很多工作示例。e、 g: import wmi c = wmi.WMI () for process in c.Win32_Process (): print process.ProcessId, process.Name 或 我很好奇我可以为WMI类初始化传递什么样的参数,并查看了源代码。我在寻找类似于类WMI:或函数def WMI(),但我发现它是这样声明的: # # class WMI
import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
print process.ProcessId, process.Name
或
我很好奇我可以为WMI类初始化传递什么样的参数,并查看了源代码。我在寻找类似于类WMI:或函数def WMI(),但我发现它是这样声明的:
#
# class WMI
#
class _wmi_namespace:
"""A WMI root of a computer system. The classes attribute holds a list
of the classes on offer. This means you can explore a bit with
things like this::
c = wmi.WMI ()
for i in c.classes:
if "user" in i.lower ():
print i
"""
def __init__ (self, namespace, find_classes):
_set (self, "_namespace", namespace)
#
# wmi attribute preserved for backwards compatibility
#
_set (self, "wmi", namespace)
self._classes = None
self._classes_map = {}
#
# Pick up the list of classes under this namespace
# so that they can be queried, and used as though
# properties of the namespace by means of the __getattr__
# hook below.
# If the namespace does not support SubclassesOf, carry on
# regardless
#
if find_classes:
_ = self.classes
正如我看到的,在注释中有一个解释它是如何工作的,但无论如何我都无法理解。
WMI
定义为WMI.py
中第1295行周围的WMI=connect
,它不是一个类,而是connect()
函数的另一个名称。
因此,要查看参数,请查看
connect()
(请记住Python是区分大小写的)
#
# class WMI
#
class _wmi_namespace:
"""A WMI root of a computer system. The classes attribute holds a list
of the classes on offer. This means you can explore a bit with
things like this::
c = wmi.WMI ()
for i in c.classes:
if "user" in i.lower ():
print i
"""
def __init__ (self, namespace, find_classes):
_set (self, "_namespace", namespace)
#
# wmi attribute preserved for backwards compatibility
#
_set (self, "wmi", namespace)
self._classes = None
self._classes_map = {}
#
# Pick up the list of classes under this namespace
# so that they can be queried, and used as though
# properties of the namespace by means of the __getattr__
# hook below.
# If the namespace does not support SubclassesOf, carry on
# regardless
#
if find_classes:
_ = self.classes