Encoding problem in python file

The third parameter can be directly added to
the
() opened by py36 with as , encoding = 'utf-8'

py27
uses .encode ('utf-8') after something inside f.write

 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)

Published 70 original articles · Likes0 · Visits 1705

Guess you like

Origin blog.csdn.net/weixin_44807751/article/details/105000666