[capi-sig] Python parser

Jon Parise jon at indelible.org
Tue May 27 22:27:36 CEST 2008


On Tue, May 27, 2008 at 12:52 PM, Pablo Yabo <pablo.yabo at gmail.com> wrote:
>
> I embedded Python in an application to play with some objects.
> I want to add some features to my console and I don't find how to evaluate
> in the same way the Python console does.
>
> I want to let the user insert a:
> for a in [1,2,3]:
>
> and I want to put the '...' like the console but if I evaluate the 'for a in
> [1,2,3]:\n' using PyRun_SimpleString I get an error:
>
>  File "<string>", line 1
>    for a in [1,2,3]:
>                   ^
> SyntaxError: unexpected EOF while parsing
>
> Is there any way to evaluate in the same way the console does?

I don't think you'll be able to get that type of behavior out of
PyRun_SimpleString().  Try taking a look at the PyRun_Interactive*()
functions and PyRun_String() with the Py_single_input start symbol.
That should get you pointed in the right direction.

-- 
Jon Parise (jon of indelible.org) :: "Scientia potentia est"


More information about the capi-sig mailing list