python 讀寫檔案編碼處理問題
#coding:utf-8
string1=u"凝固粉末冶金技術"
print string1
f = open('data.txt','w')
f.write(string1.encode(encoding='gbk', errors='ignore'))
f.close()
#errors = 'ignore' 當編碼轉換出錯時忽略錯誤
f = open('data.txt','r')
for line in f.readlines():
line.decode('gbk',errors='ignore')
print line
f.close()