我有這樣的代碼:打印的特定字段在Python 3開放
with open('/home/adiel/log', 'r') as list:
content = list.read()
rows = content.split("\n")
for row in rows:
infos = row.split(' ')
print(infos)
返回我的這些值:
['2', '064328796150', 'eni-4bad5a20', '172.18.0.124', '172.18.0.5', '3306', '39064', '6', '14', '4123', '1504618064', '1504618121', 'ACCEPT', 'OK']
['2', '064328796150', 'eni-4bad5a20', '172.18.0.124', '172.18.0.5', '3306', '62717', '6', '16', '5981', '1504618064', '1504618121', 'ACCEPT', 'OK']
['2', '064328796150', 'eni-4bad5a20', '172.18.0.5', '172.18.0.124', '52909', '3306', '6', '37', '7112', '1504618064', '1504618121', 'ACCEPT', 'OK']
我想只有從場1和4的值,例如。我怎樣才能做到這一點?
請注意,你可能不想說「的名單」,因爲「名單」是內置在Python(https://開頭的文檔.python.org/2/library/functions.html#func-list)並且這個破壞它。 「作爲list_file」可能會更清晰。 – dmcc