In off-platform-project-generative-chatbot project for ** Build Chatbots with Python Skill Path** script to read the file crashes because of emoji:
data_path = "./twitter-project/weather.txt"
# Defining lines as a list of each line
with open(data_path, 'r', encoding='utf-8') as f:
lines = f.read().split('\n')
lines = [re.sub(r"(?:\@|https?\://)\S+", "", line).strip() for line in lines]
print(lines)
returns error
line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f927' in position 94: character maps to <undefined>
I tried to add error ignore however no luck
# Defining lines as a list of each line
with open(data_path, 'r', encoding='utf-8', errors='ignore') as f:
lines = f.read().split('\n')
lines = [re.sub(r"(?:\@|https?\://)\S+", "", line).strip() for line in lines]
print(lines)
thank you for your help