Re: Simple text parsing gets difficult when line continues to next line



Jacob Rael wrote:
Hello,

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

Something like (not tested):

fp=open(filename, 'r')
for line in fp:
while line.rstrip().endswith('_'):
line+=fp.next()


fp.close()

-Larry

.



Relevant Pages

  • Re: Parsing strings via shell vars?
    ... My shell scripting must be getting rusty and a quick google isn't ... > I need to find a way to parse a shell variable rather than a file, ... > it's basically using a few system files to determine what variant of *nix ... > further filesystem checks to verify what specific flavor of *nix the script ...
    (comp.unix.shell)
  • Re: parsing command line arguments multiple times
    ... >>> i am fine with any GetOpt as long as it solves my problem. ... >> With the modules I mentoned, you can parse all provided options with one ... > thanks joe, ... > lets assume we add an option -checkflag to your script ...
    (perl.beginners)
  • Re: [KSH 88] How to use set -A when first value is -x
    ... : optional args. ... It uses getopts to parse the options (I guess that was ... obvious) and a for x in $@ to parse out the mandatory arguments. ... of the script. ...
    (comp.unix.shell)
  • Re: parsing command line arguments multiple times
    ... >> i am fine with any GetOpt as long as it solves my problem. ... > With the modules I mentoned, you can parse all provided options with one ... > The script is called ... lets assume i do not pass checkflag, then i would like to invoke script ...
    (perl.beginners)
  • Re: Can I generate an event with script?
    ... meaning since you will need to handle the event and assumedly construct ... In the called page you will need to get window.location.search and parse out ... if your iframe is contained in your main page and the iframe source is ... > I want to generate an event in my script. ...
    (microsoft.public.scripting.jscript)