Re: [問題] 如何取得系統字元編碼或使用者輸入的編碼?
※ 引述《mosquito520 ( )》之銘言:
: 請教一下各位,
: user_input = raw_input(["Search item"]).decode("編碼")
: 我需要透過decode將輸入的資料正確的轉成utf8,
: 但是在繁中WinXP底下透過sys.getdefaultencoding()取得編碼為Ascii,
: 想請教一下,
: 假設我希望可以處理多國語言,
: 要如何取得正確的編碼順利的轉成utf8呢?
: 謝謝:)
import sys
user_input = raw_input("Please input something: ")
print user_input.decode(sys.stdin.encoding).encode('utf8')
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.30.46
※ 編輯: Holocaust123 來自: 140.112.30.46 (03/15 22:52)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):