Aug-17-2020, 02:35 AM
I'm working with a large text file with the following delimited block of text:
Name: HAGNNESHSSR/3
.......
.......
Name: KAASGEAKPK/2
.......
.......
Name: HKSDFGK/2
.......
I want to parse the block of texts in between the text delimiter "Name:" at the beginning of each line. I also need rest of the Delimiter as they are of unique value.
I'm using the following code to get the delimiter and lines that follow the delim. using itertools.groupby in Python3. There are two such delimited block of texts in the toy input file.
Thanks
Name: HAGNNESHSSR/3
.......
.......
Name: KAASGEAKPK/2
.......
.......
Name: HKSDFGK/2
.......
I want to parse the block of texts in between the text delimiter "Name:" at the beginning of each line. I also need rest of the Delimiter as they are of unique value.
I'm using the following code to get the delimiter and lines that follow the delim. using itertools.groupby in Python3. There are two such delimited block of texts in the toy input file.
import itertools as it filename='myData.txt' with open(filename,'r') as f: for key,group in it.groupby(f,lambda line: line.startswith('Name:')): print (key)However, I'm getting the following output:
Output:True
False
True
False
Output:
How to get the line which begins with 'Name:'?Thanks