w ='比赛'
t ='比赛开始没多久就结束了比赛,现在没有比赛'defreplace_color(text, word):
new_word ='\033[031m'+ word +'\033[0m'# red
len_w =len(word)
len_t =len(text)for i inrange(len_t - len_w,-1,-1):if text[i: i + len_w]== word:
text = text[:i]+ new_word + text[i + len_w:]return text
print(t)print(replace_color(t, w))
END ='\033[0m'classColor:@staticmethoddef_wrap_colour(colour, args, prints, sep):if prints:for a in args:print(colour +'{}'.format(a)+ END)# Linux系统会报错return colour + sep.join('{}'.format(a)for a in args)+ END
@classmethoddefbackground(cls,*args