Whenever I print a french character (for example "é") in another file using python, it changes it to a weird character.
program.py
:
f = open("file.txt", 'w')
print("é, è, ç", file=f)
file.txt
:
�, �, �
So please does anyone know how to print out french characters to any other files as they are?
You can try using UTF-8 encoding:
f = open("french.txt", 'w', encoding='utf-8')
print("é, è, ç", file=f)
# é, è, ç
The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.
def wordlist(filename): f = open(filename, mode='r') text = f.read() print(text) wordlist = [fixCaps(w) for w in re.findall(r"[\w']+|[.,?;,]". text)] print(wordlist) f.close() return wordlist
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.