translating foreign data
Steven D'Aprano
steven.d'aprano at 1
Sun Jun 24 04:23:22 EDT 2018
From: Steven D'Aprano <steve+comp.lang.python at pearwood.info>
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'
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing it everywhere."
-- Jon Ronson
--- BBBS/Li6 v4.10 Toy-3
* Origin: Prism bbs (1:261/38)
More information about the Python-list
mailing list