On Sun, Jun 24, 2018 at 1:23 PM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > On Sun, 24 Jun 2018 12:53:49 +1000, Chris Angelico wrote: > > [...] >>> Okay, you want a bit-pattern. In hex: >>> >>> '0x313030e282ac' > [...] > >> Hmm. Actually, I'm a bit confused. >> >>>>> hex("100€".encode()) >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> TypeError: 'bytes' object cannot be interpreted as an integer >> >> Nope, that's not it. Needs something to turn the bytes into an integer >> first. But I can't find a way to do that. Best I can find is: >> >>>>> "100€".encode().hex() >> '313030e282ac' > > Dammit, that was what I was looking for, but I only looked on *strings*, > not bytes. > > >> No "0x" prefix, no function call. So, I'm stuck. How did you create your >> one? > > py> hex(int.from_bytes("100€".encode("utf-8"), 'big')) > '0x313030e282ac'
Ahhh thanks, that's the part I couldn't find (and didn't remember). Anyhow, encoding to UTF-8 and then to bytes is pretty easy. ChrisA -- https://mail.python.org/mailman/listinfo/python-list