Skip to content

Instantly share code, notes, and snippets.

@kemadz
Created May 10, 2018 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kemadz/ec877f069de5a9f2be74b2cb2b6cc12e to your computer and use it in GitHub Desktop.
Save kemadz/ec877f069de5a9f2be74b2cb2b6cc12e to your computer and use it in GitHub Desktop.
fix encoding hell
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
orig = '孃䱋崸㔴㔵'
if sys.version_info.major > 2:
print(bytes.fromhex(''.join([hex(ord(c)) for c in orig]).replace('0x', '')).decode())
else:
print(bytearray.fromhex(''.join([hex(ord(c)) for c in orig.decode('utf-8')]).replace('0x', '')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment