Re: 新手想寫登入BBS的程式(Python 3)

看板Python作者 (花生)時間10年前 (2013/11/19 17:52), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/5 (看更多)
我又做了新的測試: 程式碼: =============================================== # -*- coding: big5 -*- import telnetlib tn = telnetlib.Telnet('ptt.cc') s = tn.read_until(b"ptt3") print(s) =============================================== 會印出ptt的首頁畫面 但改成read_until(b"請輸入代號"),就不行,程式碼: =============================================== # -*- coding: big5 -*- import telnetlib tn = telnetlib.Telnet('ptt.cc') s = tn.read_until(b"請輸入代號") print(s) =============================================== 會顯示錯誤:『bytes can only contain ASCII literal characters.』 看read_until的文件,他接受的參數是byte string,所以應把字串轉成byte string 但看程式碼第一行是用big5 是不是指字串:『請輸入代號』已經是big5編碼 所以要想辦法把big5 轉成byte string ? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.200.46.75

11/19 19:11, , 1F
等等,你是用python2還是python3?
11/19 19:11, 1F

11/19 19:14, , 2F
python3 ~
11/19 19:14, 2F
※ 編輯: peanut97 來自: 60.248.161.28 (11/19 19:14)
文章代碼(AID): #1IYpJASE (Python)
討論串 (同標題文章)
文章代碼(AID): #1IYpJASE (Python)