Tuesday, January 25, 2005

pyparsing -- a class library for text processing in Python

pyparsing -- a class library for text processing in Python: "pyparsing -- an object-oriented approach to text processing in Python"

Here is a complete "Hello, World!" program, using the pyparsing module:

from pyparsing import Word, alphas, oneOf
greet = Word( alphas ) + "," + Word( alphas ) + oneOf("! ? .")
hello = "Hello, World!"
print hello, "->", greet.parseString( hello )

This program results in:

Hello, World! -> ['Hello', ',', 'World', '!']