Re: Simple text parsing gets difficult when line continues to next line
- From: Larry Bates <larry.bates@xxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 12:11:49 -0600
Jacob Rael wrote:
Hello,Something like (not tested):
I have a simple script to parse a text file (a visual basic program)
and convert key parts to tcl. Since I am only working on specific
sections and I need it quick, I decided not to learn/try a full blown
parsing module. My simple script works well until it runs into
functions that straddle multiple lines. For example:
Call mass_write(&H0, &HF, &H4, &H0, &H5, &H0, &H6, &H0, &H7, &H0,
&H8, &H0, _
&H9, &H0, &HA, &H0, &HB, &H0, &HC, &H0, &HD, &H0, &HE,
&H0, &HF, &H0, -1)
I read in each line with:
for line in open(fileName).readlines():
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?
jr
fp=open(filename, 'r')
for line in fp:
while line.rstrip().endswith('_'):
line+=fp.next()
fp.close()
-Larry
.
- References:
- Simple text parsing gets difficult when line continues to next line
- From: Jacob Rael
- Simple text parsing gets difficult when line continues to next line
- Prev by Date: Simple text parsing gets difficult when line continues to next line
- Next by Date: Reading text labels from a Win32 window
- Previous by thread: Simple text parsing gets difficult when line continues to next line
- Next by thread: Re: Simple text parsing gets difficult when line continues to next line
- Index(es):
Relevant Pages
|