[capi-sig] PyRun_InteractiveOne from string?

Dave Brotherstone davegb at pobox.com
Thu Jun 10 20:59:44 CEST 2010


Hi,

I hope I'm asking this in the right place...  I've embedded Python in an
application, and I'm now trying to emulate a "console" for immediate
commands.  I can see PyRun_InteractiveOneFlags and the variants are used to
send single statements, but there doesn't seem to be any variants that take
a string, only a FILE*.  I'm in a windows app, so there's no console.  (I
actually have effectively two text boxes, one multi-line read only for
stdout/stderr, and one input.), I know the prompt would be in the wrong
place, but that's no biggie.

PyRun_String does almost what I want, except that it fails on multiline
statements (if ... : etc).

I just wanted to check if there's an API I've missed, or, whether anyone can
recommend an approach.

I think I could either:
a) Emulate the console through an FILE* - not sure quite how this works in
Windows, but I'm sure it's possible
b) Copy what PyRun_InteractiveOneFlags() does, just replacing
the PyParser_ASTFromFile with PyParser_ASTFromString.  Only problem here is
that I seem to need mod_ty, and not sure whether it's a good idea to use
something that looks like an internal type.

Many thanks for any comments.

Dave.


More information about the capi-sig mailing list