with codecs.open(filename, 'w+b', encoding='utf-8') as fh:
    fh.write('Hello World: \xe4')
fh.seek(0)
for line in fh:
    print(line)
os.unlink(filename)
How to create a temporary file with Unicode encoding?