Validating Syntax only with PyParser_SimpleParseString ?

Fuzzyman fuzzyman at gmail.com
Wed Mar 29 10:18:27 EST 2006


gaston.gloesener at web.de 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 cptools.py (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
(sorry).

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Environment: Windows / Borland C++




More information about the Python-list mailing list