urdu 字符串看起来相同但比较发现不相等 python3

urdu strings looking same but in comparison found unequal python3

在我的应用程序中,我在文本文件中列出了(乌尔都语)单词,(目前是这样的单个单词)

我还有另一个包含乌尔都语字符串的文本文件(目前是这样的一个单词,完全相同)

现在我需要查找字符串文件的字符串是否包含任何存在于 word 文件中的单词。为此,我正在将两个文件读入这样的列表中;

// 读取字符串的文本文件...

fileToRead = codecs.open('string.txt', mode, encoding=encoding)
fileData = fileToRead.read()
lstFileData = fileData.split('\n')


wordListToRead = codecs.open('words.txt', mode, encoding=encoding)
wordData = wordListToRead.read()
lstWords = wordData.split('\n')

我只是像这样遍历列表;

for string in lstFileData:
    if string in lstWords:
        // do further work

它不起作用而且我不知道为什么?虽然字符串是 'فلسفو' 并且 lstWords 中有这个字符串。我需要添加一些编码吗?任何形式的帮助将不胜感激。

刚刚在 python3 中尝试过,它似乎对我有用:

lstWords = ['a', 'فلسفے', 'b']
string = 'فلسفے'
if string in lstWords:
    print("yes")

编辑:同样,刚刚使用文件 IO 测试了更新后的代码,它工作正常(我没有指定编码)。这是它工作的 link:https://trinket.io/python3/3890d8b261

May be it helped out someone like me

虽然听起来很有趣,但问题在 file encoding type。我在简单的记事本中打开文件进行一些更改并保存。它将我的文件从 utf-8 更改为 utf-8 BOM。而且我的代码无法正常工作。一旦我在 utf-8 的记事本 ++ 中创建了新文件,相同的代码就开始正常工作了。 (因为问题不在代码中,而是在文件编码中)