[問題]編碼的問題

看板Python作者 (I think home)時間10年前 (2015/09/23 17:30), 10年前編輯推噓1(105)
留言6則, 2人參與, 最新討論串1/1
大家好 請問一下上面有一撇的e (以下以e撇稱呼) 也就是 http://goo.gl/l4WVwv 裡的編號 U+00E9 我在excel裡面讀到e撇 encode成utf-8之後變成 \xc3\xa9 但我要怎麼把它再轉成e撇輸出到txt的文字檔案呢? 謝謝 :) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.69.226 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1443000638.A.5A3.html

09/23 17:46, , 1F
py2 or 3? 3的話 b'\xc3\xa9'.decode('utf8')
09/23 17:46, 1F

09/23 17:49, , 2F
2好像直接print就好?
09/23 17:49, 2F

09/24 08:32, , 3F
好的,我再試一下,謝謝囉 :)
09/24 08:32, 3F
※ 編輯: alair99 (140.114.69.226), 09/24/2015 14:16:22

09/24 14:19, , 4F
後來使用 namedentities 套件來把e撇轉換成 é
09/24 14:19, 4F

09/24 14:19, , 5F
這樣才能讓網頁真正呈現出e撇的文字
09/24 14:19, 5F

09/24 14:20, , 6F
語法是 repr(named_entities(string))
09/24 14:20, 6F
文章代碼(AID): #1M0d4-MZ (Python)
文章代碼(AID): #1M0d4-MZ (Python)