Help with multi-line parsing

Anonymous
2010-11-28
2013-05-14

  • Anonymous
    2010-11-28

    Hi everyone,

    I'm new to pyparsing and Python in general, so apologies if this has been answered somewhere I haven't seen yet.

    I have some files I'd like to parse but can't find anything resembling their structure in the documentation, despite it being fairly simple. An example can be seen here:

    http://pyparsing.pastebin.com/MxREVYd6

    There are two types of data I'd like to get out of this file. First, the "QTBDY" section which is a Nx2 array of numbers (0.970, 1.180, … 0.970) and (0.000, … 19.250). The second is the RIVER/SECTION, for which there are a Nx6 of mostly numbers (although the *s and LEFT/RIGHT/BED are important). Ideally I'd like to eventually get these into a numpy arrays (with an appropriate numeric conversion for the text), associated with the section name (S1, S2, etc).

    I've had some success doing this manually, line-by-line with regular expressions etc, but it's really very clunky. I was hoping pyparsing could do a better job.

    I'd appreciate any direction that you can offer.

    TIA,
    Josh.