I have a file named item.dat containing bracketed keywords:
[ITEM1]
banana
peach
apple
orange
grapes
[END]
[ITEM3]
tennis
bowling
[END]
........
I want to the lines between the bracketed keywords to be processed. The variable wil contain the bracketed lines I want to extract. The problem is how do I perform a line comparison for "[ItemName]"?
del item[:]
ItemName = "ITEM3"
with open('item.dat') as input_data:
for line in input_data:
if line.strip() == "\[ItemName\]": # the problematic line
break
for line in input_data: # This keeps reading the file
if line.strip() == '[END]':
break
print line
item.append(line)