一、代码
class Dict(dict): __setattr__ = dict.__setitem__ __getattr__ = dict.__getitem__ def dict_to_object(dictObj): if not isinstance(dictObj, dict): return dictObj inst = Dict() for k, v in dictObj.items(): inst[k] = dict_to_object(v) return inst def load_emoji_map_v2(fn='emoji_12_1.json'): json_data = json.load(open(fn, encoding='utf-8')) return json_data # 转换字典成为对象,可以用"."方式访问对象属性 def dict_to_obj(): json_data=load_emoji_map_v2() em_obj_list=[] for i in range(len(json_data)): em_obj = dict_to_object(json_data[i]) em_obj_list.append(em_obj) return em_obj_list def find_emoji(emoji): em_obj_list=dict_to_obj() for i in em_obj_list: if emoji==i.codes: return i else: return "" if __name__ == '__main__': emoji=find_emoji("1F4FB") print(emoji.codes) print(emoji.char) print(emoji.name) print(emoji.category) print(emoji.group) print(emoji.subgroup)
二、emoji的json文件
由于文件太大了,就不贴出来了,可以去github下载
https://github.com/amio/emoji.json