Re: [問題] 程式輸出 pipe redirect 與 Unicod …

看板Python作者時間17年前 (2008/09/08 19:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ 引述《bizkit.bbs@ptt.cc (靠北喔= = )》之銘言: : 我有一個程式會 print 出中文, 如下 : bash-3.2$ ./test.py : 油品行銷事業部台北市信義區松仁<b>路三號總機:(02)8789-8989 傳真:(02)8789</b>-9050 免費 服務專線:0800-036188 電子服務信箱:D001830@cpc.com.tw <b>...</b> : 地址: 11010台北市信義區松仁<b>路三號/ 總機: 02-8789-8989 / 傳真: 02-8789</b>-9000 加油 站客服電話: 0800-036188/網站瀏覽人數:3397635 人 <b>...</b> : 但是當我想把輸出寫到一個檔案 或是pipe到more的時候 : bash-3.2$ ./test.py |more : Traceback (most recent call last): : ...... : UnicodeEncodeError: : 'ascii' codec can't encode characters in position 0-14: : ordinal not in range(128) : 請問我做錯了什麼? 在 print 之前,先把字串用 utf-8 編碼 如: print u"測試" 改成: print u"測試".encode("utf-8") -- ※Post by zao from linus.csie.ntu.edu.tw 老鼠的香香乳酪洞˙電子佈告欄系統˙alexbbs.twbbs.org˙140.113.166.7
文章代碼(AID): #18nGNn00 (Python)
文章代碼(AID): #18nGNn00 (Python)