Embedding python question: PyRun_String only returns None not what I calculate

Mark Hammond MHammond at skippinet.com.au
Tue Apr 6 19:36:21 EDT 1999

Hopefully someone with more time can give a better answer...

But the short story is that PyRun_String works with statements, not
expressions.  You can use it to, eg, import modules, and even call
functions, but you cant get the result.

To see the difference, try from a Python prompt:
>>> cmd = "1+1"
>>> exec cmd
>>> eval(cmd)

You will notice that the functionality you are after is by evaluating
objects.  Thus, you need to use a different Python API.


Barry Scott wrote in message
<923433832.14002.0.nnrp-07.9e982a40 at news.demon.co.uk>...
>What I want to do is call python to run python code and return the results
>my app. But I cannot find anyway to do this.
>It would seem that I should be using PyRun_String to run a piece of python
>and return a result object to me. But I can only get a return value of
>NULL is returned if the code does not run.
>How do I get python to return 2 to me when I ask it what 1+1 is?

More information about the Python-list mailing list