Skip to content

Commit 2d03d85

Browse files
committed
Change platform loop to use a dictionary
1 parent 5c6c527 commit 2d03d85

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

qwiic_i2c/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,21 @@
6666
from .i2c_driver import I2CDriver
6767

6868
# All supported platform module and class names
69-
sub_modules = ["linux_i2c", "circuitpy_i2c", "micropython_i2c"]
70-
class_names = ["LinuxI2C", "CircuitPythonI2C", "MicroPythonI2C"]
69+
_supported_platforms = {
70+
"linux_i2c": "LinuxI2C",
71+
"circuitpy_i2c": "CircuitPythonI2C",
72+
"micropython_i2c": "MicroPythonI2C"
73+
}
7174

7275
# List of platform drivers found on this system
7376
_drivers = []
7477

7578
# Loop through all supported platform drivers, see if they're included, and
7679
# append them to the driver list if so
77-
for i in range(len(sub_modules)):
80+
for module_name, class_name in _supported_platforms.items():
7881
try:
79-
full_name = "qwiic_i2c." + sub_modules[i]
80-
sub_module = __import__(full_name, None, None, [None])
81-
_drivers.append(getattr(sub_module, class_names[i]))
82+
sub_module = __import__("qwiic_i2c." + module_name, None, None, [None])
83+
_drivers.append(getattr(sub_module, class_name))
8284
except:
8385
pass
8486

0 commit comments

Comments
 (0)