This line works perfectly in python 2.7.6, but fails in Python 3.3.5. How i can decode to hex
value in Python 3.
return x.replace(' ', '').replace('\n', '').decode('hex')
Traceback
AttributeError: 'str' object has no attribute 'decode'
To convert hexadecimal to a string, use binascii.unhexlify
.
>>> from binascii import unhexlify
>>> unhexlify(x.replace(' ', '').replace('\n', ''))
However, you first need to make x
into bytes
to make this work, for Python 3. Do this by doing:
>>> x = x.encode('ascii', 'strict')
And then do the hex-to-string conversion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With