Parsing text file with #include and #define directives

python at python at
Thu Apr 24 15:37:03 EDT 2008

I'm parsing a text file for a proprietary product that has the following
2 directives:

#include <somefile>
#define <name> <value>

Defined constants are referenced via <#name#> syntax.

I'm looking for a single text stream that results from processing a file
containing these directives. Even better would be an iterator(?) type
object that tracked file names and line numbers as it returns individual

Is there a Python parsing library to handle this type of task or am I
better off writing my own?

The effort to write one from scratch doesn't seem too difficult (minus
recursive file and constant loops), but I wanted to avoid re-inventing
the wheel if this type of component already exists.

Thank you,


More information about the Python-list mailing list