目標(biāo):我的目標(biāo)是獲取所有進(jìn)程名稱和進(jìn)程 ID,以生成這樣的輸出:{process 1: 123},{process 2: 321},{process 3: 132}然后 id 能夠使用.get()函數(shù)來(lái)獲取特定id的 .目前:我能夠做到這一點(diǎn):import wmic = wmi.WMI ()list = []for process in c.Win32_Process (): list.append(process.Name)print(list)沒有 process.ProcessId 它工作正常。錯(cuò)誤:如果我像這樣嘗試使用 process.ProcessId :import wmic = wmi.WMI ()list = []for process in c.Win32_Process (): list.append(process.Name, process.ProcessId)print(list)我收到此錯(cuò)誤: list.append(process.Name, process.ProcessId)TypeError: append() takes exactly one argument (2 given)如何創(chuàng)建字典以將這兩個(gè)值附加到一個(gè)大字典中?
如何將進(jìn)程名稱和進(jìn)程附加到字典?
慕碼人2483693
2022-11-29 15:27:47