python - Parsing with multiple identifiers -
i trying implement block of code generator not working split string particular identifier . python 2 found 2 bugs in can’t seem fix.
input: @m120204 ctct + ~@@! @this_one_has_an_at_sign ctctct + @jfik9 @thisoneisempty + #empty line after + , empty line end file (2 empty lines)
the 2 bugs are: (i) when there @ starts line of code after ‘+’ line such 2nd entry (@this_one_has_an_at_sign) (ii) when there line following @identification_line or line following ‘+’ lines empty in 3rd entry (@thisoneisempty)
i output same post referenced:
yield (name, body, extra)
in case of @this_one_has_an_at_sign
name= this_one_has_an_at_sign body= ctctct quality= @jfik9
in case of @thisoneisempty
name= thisoneisempty body= '' quality= ''
i tried using flags can’t seem fix issue. know how without using generator i’m going using big files don’t want go down path. current code is:
def organize(input_file): name = none body = '' = '' line in input_file: line = line.strip() if line.startswith('@'): if name: body, = body.split('+',1) yield name, body, body = '' name = line else: body = body + line body, = body.split('+',1) yield name, body, line in organize(file_path): print line
Comments
Post a Comment