我希望每次在文本中出现特定单词时,能以不同的颜色打印该单词。在现有代码中,我已经打印了包含相关单词“one”的行。
import json
from colorama import Fore
fh = open(r"fle.json")
corpus = json.loads(fh.read())
for m in corpus['smsCorpus']['message']:
identity = m['@id']
text = m['text']['$']
strtext = str(text)
utterances = strtext.split()
if 'one' in utterances:
print(identity,text, sep ='\t')
我导入了 Fore,但不知道在哪里使用它。我想用它来让单词 "one" 以不同的颜色显示。 输出(部分内容):
44814 哦,那就是约翰逊告诉我们的那个……你能把它发给我吗?
44870 有点……我去了,但没有其他人去,所以我和莎拉一起去吃午饭 xP
44951 不,它是在一个地方大声指引,当我停下来时它就停下来了,或多或少
44961 因为它提高了人们的意识,但没有人采取行动,我想
44984 我们需要像我们的 mcs onec 那样进行 fob 分析
谢谢