I'm trying to write the output of my script on a file.txt but when I write maybe Arabic characters the output on file is written from right to left.
this is my script:
import unicodedata
import sys
from tabulate import tabulate
headers=["Unicode Point", "Character in UTF-8 + length", "Character normalized + legth"]
data = []
f = open('multiplierNFD.txt', 'a', encoding='utf8')
for i in range (sys.maxunicode + 1):
uni = chr(i)
char8 = uni.encode('utf8', 'ignore').decode('utf8', 'ignore')
char8norm = unicodedata.normalize('NFKC', char8)
if len(char8) != len(char8norm):
if i < 65535:
str1 = "U+" + str(hex(i))[2:].rjust(4,'0')
else:
str1 = "U+" + str(hex(i))[2:].rjust(8,'0')
str2 = char8 + " ---> " + str(len(char8))
str3 = char8norm + " ---> " + str(len(char8norm))
data.append([str1, str2, str3])
f.write(tabulate(data, headers=["Unicode Point", "Character in UTF-8 + length", "Character normalized + legth"]))
and this is the example of the output:
U+fb16 ﬖ ---> 1 վն ---> 2
U+fb17 ﬗ ---> 1 մխ ---> 2
U+fb1d יִ ---> 1 יִ ---> 2
U+fb1f ײַ ---> 1 ײַ ---> 2
U+fb2a שׁ ---> 1 שׁ ---> 2
How can I avoid this and print/save the output like in the first two lines?