作者peanut97 (花生)
看板Python
标题新手想写登入BBS的程式
时间Tue Nov 19 00:13:36 2013
小弟是接触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
1F:→ ck574b027:1 跟 bbs 没有关系,它是标示这个 py 档用的编码。 11/19 00:31
2F:推 icycandle:2 可google python String literals 11/19 19:07