python处理中文文件格式

python文件本身也要存为utf-8格式,如果是从txt文本转换过来,一定要先另存为utf-8格式

TypeError: coercing to Unicode: need string or buffer, int found

unicode(dic[key1][key2]

\ufeff是windows下utf-8文本开始所带的,所以要先把它以linux的格式存,notepad,然后在进行python的处理,否则她会多一个这样的unicode字符,让人难以处理

读写中文文本

f = codecs.open(u'品牌.txt','r/w/a','utf-8')

windows下的文本读取时如果要去掉换行符:

line=line.strip('\r\n')    ##一定加\r

 

posted on 2016-11-05 12:12  stride8  阅读(217)  评论(0)    收藏  举报