Skip to content

Commit bfcbb2d

Browse files
author
Myron Sosyak
committed
Make sonic_sfp Python2 and Python3 compatible
1 parent ea59c0f commit bfcbb2d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sonic_platform_base/sonic_sfp/sfputilbase.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,15 @@ def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
338338
return None
339339

340340
try:
341-
for n in range(0, num_bytes):
342-
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
341+
# in case raw is bytes (python3 is used) raw[n] will return int,
342+
# and in case raw is str(python2 is used) raw[n] will return str,
343+
# so for python3 the are no need to call ord to convert str to int.
344+
if type(raw) == bytes:
345+
for n in range(0, num_bytes):
346+
eeprom_raw[n] = hex(raw[n])[2:].zfill(2)
347+
else:
348+
for n in range(0, num_bytes):
349+
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
343350
except Exception:
344351
return None
345352

0 commit comments

Comments
 (0)