py36
with as 打开的
()里面可以直接加上第三个参数,encoding=‘utf-8’
py27
在f.write里面的东西后面使用.encode(‘utf-8’)
with open(os.path.join(paths,'r2',
os.path.splitext(os.path.basename(ima))[0])+ ".txt", "w", encoding='utf-8') as f:
f.write("The time is:{}s".format(time.time() - t)+"\n")
for key in result:
# f.write(result[key][1].encode("utf-8")) ##py27
f.write(result[key][1])
f.write("\n")
[Refer-CB](https://www.cnblogs.com/baojun2014/p/9085533.html)