Validating Syntax only with PyParser_SimpleParseString ?

Fuzzyman fuzzyman at
Wed Mar 29 17:18:27 CEST 2006

gaston.gloesener at wrote:
> I am seeking for a method to parse single lines of Python code (infact
> they are only formulas, so I generate a line like RESULT=<formula>). I
> do only want to know if the syntax is correct and if there is an error
> best would be to know where.
> I did find PyParser_SimpleParseString which does return a node
> structure. If there is an error it seems to return NULL, while I did
> not find this documented.
> Th eproblem with this is that first I do not get th elopcation of the
> syntax error, and second I don't know what is the proper method to free
> the node structure after I got it, since I will not use it. Or is there
> any better method doing this anyway.
A better way might be to use the standard library compiler module. A
file called (part of the cherrypy project) has a very simple
example called 'unrepr' which shows how to do it.

I only have restricted internet access or I would find the URL for you


> Environment: Windows / Borland C++

More information about the Python-list mailing list