loop through each line in a text file
Alf P. Steinbach
alfps at start.no
Fri Feb 26 16:12:07 EST 2010
* qtrimble:
> I'm a python newbie but I do have some basic scripting experience. I
> need to take the line starting with "wer" and extract the year and day
> of year from that string. I want to be able to add the year and day
> of year from the last line having "wer*" to the lines occurring in
> between "wer*" lines. Python seems suitable to do this and I'm fairly
> certain I can eventually get this to work but I've been hit with a
> very short time frame so I'm looking for any generous help. The data
> below is just a sample. There are well over 500,000 lines that need
> processed.
>
> wer1999001
> 31.2234 82.2367
> 37.9535 82.3456
> wer1999002
> 31.2234 82.2367
> 37.9535 82.3456
<example>
>>> line = "wer1999001"
>>> line
'wer1999001'
>>> line[3:3+4]
'1999'
>>> line[7:7+3]
'001'
>>> _
</example>
Cheers & hth.,
- Alf
More information about the Python-list
mailing list