Parsing

Jim Shady iamshady at rediffmail.com
Thu Apr 17 06:47:21 EDT 2003


Hello,

I have a file like this:

----
[tested]
101294029
101294030

----

The structure of the file is such, with different headers and varied
numbers. The blank line exists too, before the next entry starts.

What I'd like to do is run through each entry with x.readlines() and
put all 4 elements in an array for further processing. Right now I'm
trying with:

for chunk in psfile.readlines():
    if i <= 4:
        cur_chunk.append(chunk[:-2])
        i = i+1
        if i > 4:
            i = 0
            cur_chunk = []

for x in bigchunk:
    print x

This somehow doesn't work. I am a newbie to Python and would
appreciate any help.

Thanks in advance.

Regards,
Jim




More information about the Python-list mailing list