I have a text file with some records having similar fields.
name:
Class:
Subject:
name:
Class:
Subject:
As above mentioned this file can have any number of records and I want to separate each record with respective fields. Following is how far I could reach in order to pursue this problem.
def counter(file_path):
count = 0
file_to_read = open(file_path)
text_to_read = file_to_read.readlines()
file_to_read.close()
for line in text_to_read:
if line.find('name') != -1:
count = count + 1
return count
This way i can count the no. of records present in the file and now I'm finding it difficult to split the whole text file in segments equal to no. of records.
Thanks in advance