推 CodingMan: 讀進來再輸出啊 08/11 22:38
→ coeric: read write 08/11 22:54
推 ckc1ark: ASCII是相容於UTF-8 你的需求應該有描述錯誤 08/11 23:17
→ bibo9901: open("file").read().decode("ascii").encode("utf8") 08/12 00:26
→ bibo9901: 啊...decode/encode寫反了 XDD 08/12 00:49
謝謝
但是我出現以下訊息:
Traceback (most recent call last):
File "D:\gdrive\doc\tmp.py", line 43, in <module>
f= open('AAA.txt').read().decode("ascii").encode("utf-8")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa5 in position 44:
ordinal not in range(128)
請問該怎麼解決呢
謝謝
※ 編輯: opengood5566 (111.251.212.146), 08/12/2017 12:38:19
→ bibo9901: 就代表你的檔案不是ascii啊 08/12 12:41
→ s860134: 我想你要的是 codecs.open 或是 open(file,'rb') 08/12 21:59
→ uranusjr: 根據定義 ASCII 轉 UTF-8 一行 pass 就搞定惹 08/13 01:38
→ uranusjr: 問題是你的檔案根本不是 ASCII 編碼, 其他都是白搭 08/13 01:38