没有在文件中找到项目

时间:2013-02-03 06:41:18

标签: python wxpython

这是我的代码:

for line in open(logfile):
        if "ESSID" in line:
            begin = line.replace(" ", "")
            mid = begin.replace("ESSID:", "")
            final = mid.replace('"', "")
            print final
            self.APList.SetStringItem(self.index, 0, final)
            line = open(ilogfile).readline()
            if begin in line:
                connect = "yes"
            else:
                connect = "no"
            self.APList.SetStringItem(self.index, 3, connect)  

这是它正在扫描的文件(好吧,其中之一。):

wlp2s0    IEEE 802.11bgn  ESSID:"MomAndKids"
      Mode:Managed  Frequency:2.462 GHz  Access Point: E0:91:F5:7D:C9:14
      Bit Rate=18 Mb/s   Tx-Power=20 dBm
      Retry  long limit:7   RTS thr=2347 B   Fragment thr:off
      Encryption key:off
      Power Management:off
      Link Quality=62/70  Signal level=-48 dBm
      Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
      Tx excessive retries:0  Invalid misc:603   Missed beacon:0

我正在尝试测试的主要代码:

line = open(ilogfile).readline()
            if begin in line:
                connect = "yes"
            else:
                connect = "no"

我尝试使用“final”而不是“begin”并读取整个文件而不是第一行(同时使用“final”和“begin”变量。)两者都没有用。为什么这不起作用?

如需完整资源,请访问: https://github.com/codywd/WiFiz/blob/master/main.py

编辑:缩进仅在stackoverflow中中断,而不是在实际代码中。

编辑2:另一个文件包含:

wlp2s0    Scan completed :
          Cell 01 - Address: E0:91:F5:7D:C9:14
                    Channel:11
                    Frequency:2.462 GHz (Channel 11)
                    Quality=66/70  Signal level=-44 dBm
                    Encryption key:on
                    ESSID:"MomAndKids"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                              24 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=00000278820a146f
                    Extra: Last beacon: 80ms ago
                    IE: Unknown: 000A4D6F6D416E644B696473
                    IE: Unknown: 010882840B162430486C
                    IE: Unknown: 03010B
                    IE: Unknown: 2A0104
                    IE: Unknown: 2F0104
                    IE: Unknown: 32040C121860

相关部分位于该文件的顶部。

1 个答案:

答案 0 :(得分:0)

以下似乎工作正常:

line = open(ilogfile).readline()

if final.strip() in line.strip():
    connect = "yes"
else:
    connect = "no"