新手想寫登入BBS的程式(Python 3)
小弟是接觸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
11/19 00:31, 1F
推
11/19 19:07, , 2F
11/19 19:07, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 5 篇):