Parsing files -- pyparsing to the rescue?
allanz at gmail.com
Tue Jan 17 01:06:45 CET 2006
p = re.compile(r'<SYSLIB>([^<]*)<')
s = open("file").read()
m = re.search(p, s)
if m: res = m.groups()
res = res.lstrip("\n")
res = res.rstrip("\n")
"rh0dium" <sklass at pointcircle.com> wrote in message
news:1137445296.573399.60970 at g47g2000cwa.googlegroups.com...
> Hi all,
> I have a file which I need to parse and I need to be able to break it
> down by sections. I know it's possible but I can't seem to figure this
> The sections are broken by <> with one or more keywords in the <>.
> What I want to do is to be able to pars a particular section of the
> file. So for example I need to be able to look at the SYSLIB section.
> Presumably the sections are
> Sys Data
> <SOME SECTION>
> So if I wanted to break them down..
> Sections are broken down by this..
> secH=pyparsing.LineStart() + pyparsing.Suppress(
> pyparsing.Literal("<")) +
> pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums)) +
> pyparsing.Suppress( pyparsing.Literal(">"))
> But how do I say that <SECTIONn> stops at the start of the next
More information about the Python-list