From bfcbb2daf1e9405aa4c93fa1f7d25477a17fb5ba Mon Sep 17 00:00:00 2001 From: Myron Sosyak Date: Mon, 4 Jan 2021 06:15:02 -0800 Subject: [PATCH] Make sonic_sfp Python2 and Python3 compatible --- sonic_platform_base/sonic_sfp/sfputilbase.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sonic_platform_base/sonic_sfp/sfputilbase.py b/sonic_platform_base/sonic_sfp/sfputilbase.py index 74c420bb0..2a4cc363b 100644 --- a/sonic_platform_base/sonic_sfp/sfputilbase.py +++ b/sonic_platform_base/sonic_sfp/sfputilbase.py @@ -338,8 +338,15 @@ def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes): return None try: - for n in range(0, num_bytes): - eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2) + # in case raw is bytes (python3 is used) raw[n] will return int, + # and in case raw is str(python2 is used) raw[n] will return str, + # so for python3 the are no need to call ord to convert str to int. + if type(raw) == bytes: + for n in range(0, num_bytes): + eeprom_raw[n] = hex(raw[n])[2:].zfill(2) + else: + for n in range(0, num_bytes): + eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2) except Exception: return None