0

如果我的第一行为真(6c00ff00 = 1),我需要在 python 中编写一个脚本来查找第 7 行的输出,即“y”。我能够在一个文件中捕获所有这些值(比如“xyz”),但我无法在文件中进行比较。

>>> vi xyz

6c00ff00 = 1
6c01ff00 = BGSV 1
6c02ff00 = 08IS01191025
6c03ff00 = 192.11.13.5
7005ff00 = g430
e808ff00 = 249
6c0aff00 = y
7002ff00 = 35 .4  .0  /
7001ff00 = 0
7b00ff00 =
7100ff00 = 1
7003ff00 = 192.11.13.150
4

1 回答 1

0
with open('xyz') as infile:
  line1 = infile.readline().strip()
  for _ in xrange(6):
    line7 = infile.readline()
  line7 = line7.strip()
  print "The first line is '%s'" %line1
  print "The seventh line is '%s'" %line7
  if line1.split('=')[1].strip() == '1':
    if line7.split('=')[1].strip() == 'y':
      print "Correct"
    else:
      print "Wrong"
于 2013-10-16T05:37:17.080 回答