Simple text parsing gets difficult when line continues to next line
Roberto Bonvallet
Roberto.Bonvallet at cern.ch
Tue Nov 28 13:13:07 EST 2006
Jacob Rael wrote:
[...]
> I would line to identify if a line continues (if line.endswith('_'))
> and concate with the next line:
>
> line = line + nextLine
>
> How can I get the next line when I am in a for loop using readlines?
Don't use readlines.
# NOT TESTED
program = open(fileName)
for line in program:
while line.rstrip("\n").endswith("_"):
line = line.rstrip("_ \n") + program.readline()
do_the_magic()
Cheers,
--
Roberto Bonvallet
More information about the Python-list
mailing list