a = tempfile.TemporaryFile(mode='w') b = codecs.getencoder('utf-16')(a) b.write("someting is thees!")