!pip install emot
from emot.emo_unicode import EMOTICONS_EMO
def convert_emoticons(text):
for emot in EMOTICONS_EMO:
text = re.sub(u'\('+emot+'\)', "_".join(EMOTICONS_EMO[emot].replace(",","").split()), text)
return text
text = "Hello :-) :-)"
convert_emoticons(text)
我试图在google collab中运行上面的代码,但它给出了以下错误:unbalanced parenthesis at position 4
我对 re 模块文档的理解告诉我这'\(any_expression'\)'
是正确的使用方式,但我仍然得到错误。所以,我尝试替换'\(' + emot + '\)
为:
'(' + emot + ')'
,它给出了同样的错误'[' + emot + ']'
,它给出以下输出:Hello Happy_face_or_smiley-Happy_face_or_smiley Happy_face_or_smiley-Happy_face_or_smiley
正确的输出应该Hello Happy_face_smiley Happy_face_smiley
是text = "Hello :-) :-)"
有人可以帮我解决问题吗?