我有以下代碼:一個比較x.split()[現場]一些值
with open('/home/adiel/log', 'r') as f:
for line in [[x.split()[3], x.split()[4], x.split()[5], x.split()[6]] for x in f]:
print(line)
它工作正常,併爲我打印這些值:
['172.18.0.124', '172.18.0.5', '3306', '39064']
['172.18.0.124', '172.18.0.5', '3306', '62717']
['172.18.0.5', '172.18.0.124', '52909', '3306']
['172.18.0.5', '172.18.0.124', '13989', '3306']
但我想將x.split()[5]
與443
或65535
等一些值進行比較,只有與它們匹配時纔打印行。 我該如何做到這一點? 感謝的
呃......''x.split()[3],x.split()[4],x.split()[5],x.split()[6]]'x.split ()[3:7]',不是嗎? – DyZ
'if line [2] ==:print(line)' –
對不起,我是初學者,忘記了,但是,完成了:for [x.split()[3:7]] for x in f]: – Adiel