Skip to content

Instantly share code, notes, and snippets.

@zhaocai
Last active October 19, 2016 01:14
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 zhaocai/08335720c924ee9ae27081a941759ecc to your computer and use it in GitHub Desktop.
Save zhaocai/08335720c924ee9ae27081a941759ecc to your computer and use it in GitHub Desktop.
decode utf16
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import codecs
encoded_text = open(sys.argv[-1], 'rb').read()
bom= codecs.BOM_UTF16_LE
assert encoded_text.startswith(bom)
encoded_text= encoded_text[len(bom):]
decoded_text= encoded_text.decode('utf-16le')
sys.stdout.write(decoded_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment