Reputation: 932
I have a file with a list of unicode code points:
0x9C00
0x9D70
0x9D6B
0xFA2D
I'm trying to create an array of unicode characters, like so:
with open("KANJI.TXT") as f:
kanjiCodes = f.readlines()
alphabet = [
code_point for code_point in kanjiCodes
]
How can I convert these 0x strings to actual unicode strings?
Upvotes: 2
Views: 108
Reputation: 238975
In python 3.x you could do as follows:
kanjiCodes=['0x9C00', '0x9D70','0x9D6B', '0xFA2D']
print([chr(int(code_point, 16)) for code_point in kanjiCodes])
# ['鰀', '鵰', '鵫', '鶴']
Upvotes: 1