Skip to content

Instantly share code, notes, and snippets.

@zhaocai
Last active October 19, 2016 01:14
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