[Python] Big5 與 UTF-8 檔案編碼轉換解決方式(encoding)
Big5 轉 UTF-8
# 開啟 Big5 輸入檔案 inF = open("big5_input.txt", "r", encoding = "Big5") # 開啟 UTF-8 輸出檔案 outF = open("utf8_output.txt", "w", encoding = "UTF-8") # 以 Big5 編碼讀取檔案 content = inF.read() # 以 UTF-8 編碼寫入檔案 outF.write(content) # 關閉檔案 inF.close() outF.close()
# 使用 with 的寫法 with open("big5_input.txt", "r", encoding = "Big5") as inF, open("utf8_output.txt", "w", encoding = "UTF-8") as outF: outF.write(inF.read())
UTF-8 轉 Big5
相反寫即可
熱門評論