This is follow up to this question - 2d list in python
The answer by @Kroolik addresses my issue, but I'm stuck on another thing
consider my files is as follows
junk....
junk....
junk
required....
junk...
required....
junk...
when i read thro csv.dictreader, how do I skip the junk lines? also, I only know the first and last 'required' and the 'junk' in between. The initial 'junk' can be anything and any number of lines.
I tried the below
version_new = open(file_version_new, 'r')
flag = 0
for row in version_new:
if "JID" in row:
flag = 1 #starting of the 'required section
if "Total text" in row:
flag = 2 #end of required section
if flag == 1:
list_top_version_new.append(row.split())
if flag == 2:
#do something
reader = csv.DictReader(list_top_version_new)
for line in reader:
print(line)
but this doesnt seem to work. Any help would be appreciated. thanks