file io - How to get text between 2 lines with PYthon -
so have text file structured this:
product id list: abb: 578sh8 efc025 efc967 cnc: hdj834 hsla87 ... ... this file continues on many companies' names , id's below them. need id's of chosen company , append them list, used search website. here current line have data:
pid = open('pid.txt').read().split() this works great if there product id's of 1 company in there , no text. not work plan on doing however... how can have reader read (an example) after says abb: before next company? thinking maybe add kind of thing in file abb end know cut to, still don't know how cut out between lines in first place... if let me know, great!
two consecutive newlines act delimeter, split there construct dictionary of data:
data = {i.split()[0]: i.split()[1:] in open('pid.txt').read().split('\n\n')}
Comments
Post a Comment