编程语言
首页 > 编程语言> > python文件读取不会读取许多表情符号字符

python文件读取不会读取许多表情符号字符

作者:互联网

我在json文件中有一个1500表情符号字符列表,我想将它们导入我的python代码,我做了一个文件读取并将其转换为python字典,但现在我只有143条记录.如何将所有表情符号导入我的代码,这是我的代码.

import sys
import ast

file = open('emojidescription.json','r').read()
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
emoji_dictionary = ast.literal_eval(file.translate(non_bmp_map))

#word = word.replaceAll(",", " ");

keys = list(emoji_dictionary["emojis"][0].keys())
values = list(emoji_dictionary["emojis"][0].values())

file_write = open('output.txt','a')

print(len(keys))
for i in range(len(keys)):
    try:
        content = 'word = word.replace("{0}", "{1}")'.format(keys[i],values[i][0])
    except Exception as e:
        content = 'word = word.replace("{0}", "{1}")'.format(keys[i],'')
    #file.write()
    #print(keys[i],values[i])
    print(content)


file_write.close()

这是我的输入样本

{

    "emojis": [
        {

            "

标签:python,unicode,emoji,python-unicode
来源: https://codeday.me/bug/20190522/1154049.html