I have this function for listing all the PNPdevices of a system. The issue is, even though the query and appended object is perfect, the list to which the object is being appended , copies the entire list with only the last object.
def getnicinfo():
c = wmi.WMI()
wql = "SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter=true AND Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\%'"
temp = c.query(wql)
x = data.device() //user-defined class, does not really matter as the data exchanged is compatible
deviceList = list()
print("\nreturns physical NIC")
for J in temp:
x.ProductName = J.__getattr__('ProductName')
deviceList.append(x)
for i in deviceList: // this is where the last element that was added in last loop replaces every other element
print(i.ProductName)
return deviceList
This should print the following :
Intel(R) HD Graphics Family
Intel(R) 8 Series USB Enhanced Host Controller #1 - 9C26
Generic USB Hub
ACPI Lid
whereas the output is
ACPI Lid
ACPI Lid
ACPI Lid
ACPI Lid
As you can see it copies the last object for all the objects. The previous output that I got was by printing the deviceList[-1].ProductName
just after the append
statement, hence the object being added is correct. However, as soon as I exit the first loop and go the second (print) loop, the objects are copied.