如何在lis中修复阿拉伯语unicode

2024-09-30 01:30:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我建立了一个包含阿拉伯语单词的数据库,当我获取数据并打印出来时,它可以正常工作并打印:

مشاعر‬

مودة     

但当我循环到那个数据库,把它变成一个列表,然后打印这个列表,看看发生了什么,我得到:

 ['\u202b\u202bمشاعر\u202c', '\u202b\u202bالمودة\u202c']

代码如下:

    cors.execute("SELECT * FROM DictContents") # Selecting from database

    self.AraList = [] # empty list to put arabic words in

    for raw in cors.fetchall(): # fetching data from database

        rawAra = raw[1] # the database includes more than that so this index refer to arabic table
        print(rawAra) # here is the first print . works fine as i said .
        self.AraList.append(rawAra)
    print(self.AraList) # here is the other list printing 

在我要求之前,我试过不止一种方法来修复它,但没有一种方法对我有效。你知道吗


Tags: thetofromself数据库列表databaselist
1条回答
网友
1楼 · 发布于 2024-09-30 01:30:59

找到。。。你知道吗

import re
cors.execute("SELECT * FROM DictContents") 

self.AraList = [] 

for raw in cors.fetchall(): 

    rawAra = raw[1] 
    cleanit = re.compile('\w+.*')
    cleanone = cleanit .search(rawAra)
    if cleanone:
            print(cleanone.group()) # prints the clean strings : مشاعر‬ مودة 
    self.AraList.append(cleanone.group()) # adding strings to list to see how it will looks like .
print(self.AraList) # prints much better clean list than firs one 
['مشاعر\u202c - ', 'المودة\u202c']

相关问题 更多 >

    热门问题