我需要在python中编写一个脚本来查找第7行的输出,如果我的第一行为真(6c00ff00 = 1)则为“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
答案 0 :(得分: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"