how to get hex string from a HexBytes object?
Asked Answered
L

3

26
>>> from hexbytes import HexBytes
>>> ...
>>> hb
HexBytes('0x53b983fe73e16f6ed8178f6c0e0b91f23dc9dad4cb30d0831f178')

I have a HexBytes object hb.

I want to get 0x53b983fe73e16f6ed8178f6c0e0b91f23dc9dad4cb30d0831f178 string, what should I do?

Lody answered 24/5, 2018 at 11:38 Comment(0)
C
53

You can just type hb.hex() and it should work

Civvies answered 31/7, 2018 at 10:12 Comment(0)
F
1

never worked with this module but this should do the job:

hexdecimal = "".join(["{:02X}".format(b) for b in hb])
Franza answered 24/5, 2018 at 12:10 Comment(0)
H
1

.hex() does not work anymore with hexbytes >= 1.0

It reverts to parent class behaviour.

Now you should use the method .to_0x_hex().

I just debugged this on a new build of our software which pulls in a library that pulls in hexbytes. The latest version of the library we use has actually fixed the requirement for hexbytes to be <0.4 (latest before 1.0 is 0.3.1) i assume because of this. Unfortunately we do not use that yet :)

Houseyhousey answered 10/4 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.