I have an input text file which I am reading and storing everything in a list. After that I’m splitting the list according to the specific text occurence in the list.
Here is the function.
import re
def readFile1(file1):
f = file1.read().split('\n')
#print f
ctrlList1 = []
mfcList1 = []
for str in f:
if re.search("MegaMon> mfc",str):
print "splitting\n"
break
else:
ctrlList1.append(str)
print ctrlList1, "\n\n\n"
This works fine and saves ctrlList1 until the text megamon> mfc appears in the main list. But I want to save the lines after MegaMon> mfc in mfcList1. I am not able to do that.
I tried:
if not re.search("MegaMon> mfc", str):
print "splitting\n"
continue
else:
mfcList1.append(str)
but this doesn’t seem to be working. I need to save the text file in two different lists. Any help would be appreciated.
how about