I have a Python script that counts the number of connections contained in a text file and is working perfectly:
with open('1zao.txt') as f:
linhas = f.readlines()
soma = 0
for linha in linhas:
soma += int(linha.strip().split(" ")[0])
print("O total por segundo eh",soma)
Where 1zao.txt looks like this:
1 10:19:00 192.168.91.115
1 10:19:00 192.168.91.119
1 10:19:00 192.168.91.122
1 10:19:00 192.168.91.133
3 10:19:00 192.168.91.137
1 10:19:00 192.168.91.149
1 10:19:00 192.168.91.180
1 10:19:00 192.168.91.49
1 10:19:00 192.168.91.73
1 10:19:00 192.168.91.76
1 10:19:00 192.168.91.90
1 10:19:00 192.168.91.96
1 10:19:01 192.168.91.108
1 10:19:01 192.168.91.119
1 10:19:01 192.168.91.124
Number | schedule | IP
The input files are all of the form 1zao.txt,2zao.txt... 80zao.txt
I would like to modify the above Python script so that I do not have to be swapping the name of the text file every time I run it.
Gostaria que a saída fosse num arquivo, por exemplo resultado.txt:
1-> O total por segundo no arquivo 1zao.txt é: soma
2-> O total por segundo no arquivo 2zao.txt é: soma
Is it possible?