Python 3 has full Unicode support and has default encoding as UTf-8.
Always for file out and in use UTF-8,
do not encode decode anything if not necessary as for taking text(Unicode as default) out and in from Python 3.
Always for file out and in use UTF-8,
do not encode decode anything if not necessary as for taking text(Unicode as default) out and in from Python 3.
s = 'Crème and Spicy jalapeño ☂' with open('unicode.txt', 'w', encoding='utf-8') as f_out: f_out.write(s)Output on disk.
Output:Crème and Spicy jalapeño ☂
Read in:with open('unicode.txt', encoding='utf-8') as f: print(f.read())
Output:Crème and Spicy jalapeño ☂