Code
fileopen = open('log.txt', mode="wa") fileopen.write(message.chat.username + ' ' + message.text + '\n') I write a bot for Telegram in python 2.7 . message is an object that can output utf-8 characters in Russian , including message.text.username and message.text . How to make the interpreter correctly output everything to a file and transfer it where I have '\ n' to the next line in the file
Mistake
fileopen.write(message.chat.username + ' ' + message.text + '\n') UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-12: ordinal not in range(128)
type()). Useio.open(), explicitly specifying the encoding to write Unicode to the file. - jfs