>>> from hexbytes import HexBytes
>>> ...
>>> hb
HexBytes('0x53b983fe73e16f6ed8178f6c0e0b91f23dc9dad4cb30d0831f178')
I have a HexBytes object hb
, I want get the '0x53b983fe73e16f6ed8178f6c0e0b91f23dc9dad4cb30d0831f178' string, what should I do?
To convert byte array to a hex value, we loop through each byte in the array and use String 's format() . We use %02X to print two places ( 02 ) of Hexadecimal ( X ) value and store it in the string st .
Use the hex() Method to Convert a Byte to Hex in Python The hex() method introduced from Python 3.5 converts it into a hexadecimal string. In this case, the argument will be of a byte data type to be converted into hex.
hexbytes: Python `bytes` subclass that decodes hex, with a readable console output.
You can just type hb.hex()
and it should work
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