Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • chars_out.append('_{}_'.format(encode(char.encode(), 'hex').decode('ascii'))) what does this do? Commented Aug 16, 2015 at 13:31
  • encode the whole binary string as base 32 or base 64 like in MIME Commented Aug 16, 2015 at 13:41
  • @RishavKundu It inserts a hex unicode representation of the character between underscores, which are the only character I can reasonably use for an escape sequence. >>> '_{}_'.format(encode('π'.encode(), 'hex').decode('ascii')) prints out '_cf80_' Commented Aug 16, 2015 at 14:17
  • @Techdragon see my answer! Python will do all the work for you! Commented Aug 16, 2015 at 14:18
  • @RishavKundu You definitely gave me some new ideas for how to try building this, but your code is python 2.x only. I'm unable to use Python 2.x code, I've deprecated it in all of my projects, and any 2.x only code now fails my test suites. Using the b32encode/b32decode requires a bytes object, and the bytes object doesn't concatenate so nicely with strings. which is why I wrote '_{}_'.format(encode(char.encode(), 'hex').decode('ascii')) instead of something like '_{}_'.format(base64.b16encode('π'.encode('utf-8'))) Commented Aug 16, 2015 at 15:07