R.G. R.G. - 6 months ago 8x
Python Question

Write String of Hexadecimal Numbers to UTF-16 File

I have a long string containing hexadecimal numbers that are representations of UTF-16LE characters. Example: "59006500730020007300690072002100"

I need to make this string into an UTF-16LE file. (You know, the ones that are an unreadable mess if you open them with the MS Notepad) The string itself does not need any conversion, it already contains the raw hex data you would see when you open a UTF-16LE file with a hex editor.

I've tried various things, but I can't get Python to just make the string into an UTF-16LE file. I originally wrote the code in Java, and there

did the trick.

Any ideas how to do this in Python?


Decode it to bytes then write it to a file as binary.

with open('text.txt', 'wb') as fp: