Identify and perform actions to data within stated limits

dasacc at gmail.com dasacc at gmail.com
Tue Mar 1 15:08:22 EST 2005


Hi, I've only been using python for two days now but I'm working on it.
I have the following text:

<select><option></option><option></option></select><select><option></option></select>

My question is how can I specify to only work with the first instance
of <select>...</select> via any sort of substitute. If that isn't
possible this is what I was doing with bash script

I seperated the items as follows
<select>
<option></option>
<option></option></select>
<select>
<option></option><select>

Select has a 'name' value and i want to substitute <option> with that
name value. In bash I grep'd for the first instance of <option> and
used awk to grab the line number, subtracted the line number by one
which gave me the select are with the name value. The select had
already been parsed so that the 'name' value was first. I then assigned
that 'name' value to a variable and did a substitue via sed on the
specified line number and looped this until my line number minus 1
equaled -1.

I've been trying to figure out how to do something similar in python. I
can get my variable set, but I'm trying to figure out how to target the
first instance of whatever I specify.

I was also thinking that if I have it split up like
<select><option></option><option></option></select>
That I could specify a substitution on just that line. This would be
the best scenerio for my feeble mind to comprehend I believe.

Can anyone help me (or point me to helpful documentation) to identify
line numbers and perform substitutions on only the specified line
number or something similar?

Thanks,
Daniel




More information about the Python-list mailing list