I have the following log files and I want to split it and put it in an ordered data structure(something like a list of list) using Python 3.4
The file follows this structure:
Month #1
1465465464555
345646546454
442343423433
724342342655
34324233454
24543534533
***Day # 1
5465465465465455
644654654654454
4435423534833
***Day #2
24876867655
74654654454
643876867433
***Day #3
445543534655
344876867854
64365465433
Month #2
7454353455
84756756454
64563453433
***Day # 1
44756756655
34453453454
243867867433
***Day #2
64465465455
74454353454
34878733
***Day #3
1449898955
643434354
843090909888433
The aim is to be able to cycle on the number of months and be able to work on each day separately. I should be able to do something like this:
for month in months:
for day in days:
for number in day:
print(number)
The solution I have adopted to extract months from the file is the following, but it's not a smart solution. I need something better
lista = []
in_file = open("log.txt","r")
righe= in_file.readlines()
in_file.close()
for i in range(0,len(righe)):
if "Month" in righe[i]:
lista.append(i)
lista.append((len(righe)-1))
counter = 1
for i in range(0,len(lista)-1):
out_file = open(str(counter)+".txt","w")
for j in range(lista[i], lista[i+1]):
out_file.write(righe[j])
out_file.close()
counter=counter+1
for i in range(1,counter):
print("Month: ", i)
mano = open(str(i)+".txt","r")
righe= mano.readlines()
print(righe)
mano.close()