Re: [問題] unicode裡有str資料該怎麼轉?
只好用try解決了……
def try_to_unicode(text):
encs = ['iso-8859-1','iso-8859-2'] ## 可以任意增加編碼
#print("try: "+repr(text))
for i in encs:
try:
t = text.encode(i).decode('utf-8')
except UnicodeEncodeError:
continue
#print(" "+i+" is right code")
return t
return text
如果有更好的方法也請指教一下。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.109.254.74
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1454557391.A.169.html
→
02/04 22:49, , 1F
02/04 22:49, 1F
→
02/04 22:52, , 2F
02/04 22:52, 2F
→
02/04 22:53, , 3F
02/04 22:53, 3F
→
02/04 22:56, , 4F
02/04 22:56, 4F
→
02/04 22:56, , 5F
02/04 22:56, 5F
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):