Time script help sought!

Paul McGuire ptmcg at austin.rr._bogus_.com
Tue Jan 11 18:28:54 EST 2005


<sp1d3rx at gmail.com> wrote in message
news:1105485509.346577.292130 at f14g2000cwb.googlegroups.com...
> man, now that is beautifully done.  Paul, I wish I knew about pyparsing
> a while ago. I could have used it in a few projects. :)
>
Thanks for the compliment!  I'll be the first to admit that pyparsing can be
a bit persnickety in some applications, especially when you have to trap on
end-of-line, or have some columnar-dependent syntax.  pyparsing really works
best with data that has some syntactic structure to it, but is not
whitespace sensitive (pyparsing's default behavior is to skip over
whitespace).  I don't recommend it when the data is well-formed - regexp's
or even just string.split() will blow it away from a performance (and
simplicity) standpoint.  For instance, if the OP knew that all his data was
itemId, tapeId, recordNum, startTime, endTime, comment, he could have most
easily parsed it with

item, tape, recordNum, startTime, endTime, comment = dataline.split(None,5)

It's just those optional and variable-formatted fields that getcha. :)

-- Paul

pyparsing can be downloaded at http://pyparsing.sourceforge.net.





More information about the Python-list mailing list