[問題] 成功使用GData並列出中文標題
初發文請多指教:p
最近開始想把Python學好當做平常會用的工具
當前想做的一件事:自動改程式作業+成績填到google docs上
安裝了GData到連線登入都沒問題
但是跑測試的sample列出文件時出了問題
查了一些資料
應該是中文以及檔名長度的問題
雖然try and error後解決了...
想請高手來解釋一下背後的原因
感激不盡
原本sample code:
print '%-18s %-12s %s' % (truncate(entry.title.text.encode('UTF-8')), ...
錯誤訊息:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 0:
ordinal not in range(128)
修改後:
print '%-40s %-12s\n %s\n' % \
(truncate(entry.title.text.encode('utf8').decode('utf8')) \
.encode('big5'), ...
就可以印出中文標題了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.208.68
→
11/09 02:42, , 1F
11/09 02:42, 1F
→
11/09 02:43, , 2F
11/09 02:43, 2F
→
11/09 02:46, , 3F
11/09 02:46, 3F
→
11/09 02:46, , 4F
11/09 02:46, 4F
→
11/09 02:48, , 5F
11/09 02:48, 5F
※ 編輯: terry0201 來自: 140.113.208.68 (11/12 16:23)
Python 近期熱門文章
PTT數位生活區 即時熱門文章
14
26