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

看板Python作者 (花生)時間10年前 (2013/11/19 00:13), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/5 (看更多)
小弟是接觸Python一週的新手, 讀了《深入淺出程式設計》後,想寫個程式看看。 Google和爬文後 寫了以下程式碼: #!/usr/bin/python # -*- coding: big5 -*- import telnetlib tn = telnetlib.Telnet('ptt.cc') tn.expect(['請輸入代號']) tn.write('asdfjkl\r\n') 但卻顯示: Traceback (most recent call last): File "C:/Users/Peanut/PythonProject/LoginPTT/loginPTT.py", line 5, in <module> tn.expect(['請輸入代號']) File "C:\Python33\lib\telnetlib.py", line 652, in expect return self._expect_with_select(list, timeout) File "C:\Python33\lib\telnetlib.py", line 735, in _expect_with_select m = list[i].search(self.cookedq) TypeError: can't use a string pattern on a bytes-like object 把'請輸入代號'前面加b,變成:tn.expect([b'請輸入代號']) 按F5執行,就跳出bytes can only contains ASCII literal characters. 請問各位前輩, 1.程式開頭指定用big5 是什麼意思? 在這種bbs的環境下是適合的嗎? 2.在b'字串' ,這個代表什麼函意呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.24.92.67

11/19 00:31, , 1F
1 跟 bbs 沒有關係,它是標示這個 py 檔用的編碼。
11/19 00:31, 1F

11/19 19:07, , 2F
2 可google python String literals
11/19 19:07, 2F
文章代碼(AID): #1IYZooC_ (Python)
文章代碼(AID): #1IYZooC_ (Python)