python写文件乱码

在写入文件的时候在window上可能会出现乱码,改进方法是:在打开文件的时候设置如utf-8编码即可。

if title is not None:
            self.file = open(title+".txt","w+",encoding='utf-8')
        else:
            self.file = open(self.defaultTitle+".txt","w+",encoding='utf-8') 

 

posted @ 2015-10-15 11:05  PyJava老鸟  阅读(504)  评论(0编辑  收藏  举报