Subject: Use enumerate instead of range and len From: Radostin Stoyanov rstoyanov1@gmail.com Wed Oct 11 12:36:03 2017 +0100 Date: Fri Oct 20 13:18:31 2017 -0400: Git: f41aafc721e8fbe9baa0bc52ec9482ae3e5666ae diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py index cf860e63..3793006c 100644 --- a/virtManager/addhardware.py +++ b/virtManager/addhardware.py @@ -594,9 +594,8 @@ class vmmAddHardware(vmmGObjectUI): vmmAddHardware.populate_smartcard_mode_combo(vm, combo) idx = -1 - for rowid in range(len(combo.get_model())): + for rowid, row in enumerate(combo.get_model()): idx = 0 - row = combo.get_model()[rowid] if row[0] == virtinst.VirtualSmartCardDevice.MODE_DEFAULT: idx = rowid break @@ -641,9 +640,8 @@ class vmmAddHardware(vmmGObjectUI): vmmAddHardware.populate_tpm_type_combo(vm, combo) idx = -1 - for rowid in range(len(combo.get_model())): + for rowid, row in enumerate(combo.get_model()): idx = 0 - row = combo.get_model()[rowid] if row[0] == virtinst.VirtualTPMDevice.TYPE_DEFAULT: idx = rowid break diff --git a/virtManager/netlist.py b/virtManager/netlist.py index 4f1e991a..0bb17965 100644 --- a/virtManager/netlist.py +++ b/virtManager/netlist.py @@ -288,8 +288,8 @@ class vmmNetworkList(vmmGObjectUI): model.insert(0, row) default = 0 elif label: - default = [idx for idx in range(len(model)) if - model[idx][2] == label][0] + default = [idx for idx, model_label in enumerate(model) if + model_label[2] == label][0] _add_manual_bridge_row() return default diff --git a/virtManager/systray.py b/virtManager/systray.py index ff550738..aa62df0a 100644 --- a/virtManager/systray.py +++ b/virtManager/systray.py @@ -274,7 +274,7 @@ class vmmSystray(vmmGObject): vm_submenu.insert(menu_item, 0) return - for i in range(0, len(vm_names)): + for i, name in enumerate(vm_names): name = vm_names[i] connkey = vm_mappings[name] if connkey in self.conn_vm_menuitems[uri]: diff --git a/virtinst/cloner.py b/virtinst/cloner.py index 7345bdad..9be5485c 100644 --- a/virtinst/cloner.py +++ b/virtinst/cloner.py @@ -430,8 +430,7 @@ class Cloner(object): iface.macaddr = mac # Changing storage XML - for i in range(len(self._original_disks)): - orig_disk = self._original_disks[i] + for i, orig_disk in enumerate(self._original_disks): clone_disk = self._clone_disks[i] for disk in self._guest.get_devices("disk"):