translating foreign data

Chris Angelico chris.angelico at 1
Sun Jun 24 13:53:48 EDT 2018


From: Chris Angelico <rosuav at gmail.com>

On Sun, Jun 24, 2018 at 12:44 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> You're joking, right? You can't possibly be so ignorant as to actually
> believe that. You have, right in front of you, a news post or email
> containing the text string "100ΓΘ¼", and yet you are writing apparently in
> full seriousness that it is impossible to get that text string in a file.
>
> Okay, you want a bit-pattern. In hex:
>
> '0x313030e282ac'
>
> I'll leave the question of how I generated that as an exercise. (Hint: it
> was a one-liner, involving two method calls and a function call, all
> builtins in Python.)

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'

No "0x" prefix, no function call. So, I'm stuck. How did you create your one?

ChrisA

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)



More information about the Python-list mailing list