Python 中的希伯来语 unicode

HaR*_*ReL 2 python unicode hebrew python-2.7

我正在尝试制作英语-希伯来语词典。
我有一个 Tab 格式的字典 ( <word>TAB<translation>)。最后 - 我希望它是 mobi 格式。我找到了从选项卡转换为 opf(和 html)的 Python 脚本。从那里很容易转换为mobi。名为tab2opf.py的 Python 脚本。

当我将原始文件与 tab(.txt) 文件一起使用时 -一切都很好
我正在使用带有内置 utf 选项的脚本:tab2opf.py -utf tab.txt

问题是我想要 Kindle 的字典。Kindle 向后显示希伯来语翻译。所以我决定编辑 tab2opf 文件,这样他就可以反转翻译 - 在 Kindle 中它会正确显示。

我写了以下代码:

def RevIt(s):
heb = []
g = ""
for i in range(len(s)):
    c = s[i]
    heb.append(c)
for i in range(len(heb)):
g += heb.pop()
return g
Run Code Online (Sandbox Code Playgroud)

在 tab2opf.py 中,我在第 245 行之后添加dd = RevIt(dd)
现在我收到一团糟:
"-? ?????£??????©?????????????,)¨?????????:???? ???????,& .?????
为了比较,这是原始 txt 文件中同一行的样子:
?? ???. &, ??????? (????: ???? ?????), ???? ?? ?? ????? ?????? ????? "?-"

我究竟做错了什么?

Mar*_*som 5

您正在使用字节而不是 Unicode 字符。尝试这个:

g = u""
s = s.decode('UTF-8')
Run Code Online (Sandbox Code Playgroud)