AttributeError: 'str' object has no attribute 'decode'

подскажите как переделать код для python 3.7

# код на python 2.7

message_len = bin(message_len).lstrip('0b').zfill(4)
class_access = bin(class_access).lstrip('0b').zfill(3)
direct = bin(direct).lstrip('0b')
return str(hex(int('0b' + direct + class_access + message_len, base=2))).lstrip('0x').decode("hex")

Ошибка

# ошибка на python 3.7

return str(hex(int('0b' + direct + class_access + message_len, base=2))).lstrip('0x').decode("hex")
AttributeError: 'str' object has no attribute 'decode'

Ответы (1 шт):

Автор решения: Jaz Martin

bytes.fromhex() = .decode("hex")

return bytes.fromhex(str(hex(int('0b' + direct + class_access + message_len, base=2))).lstrip('0x'))
→ Ссылка