From: MHammond at skippinet.com.au (Mark Hammond)
Date: Wed, 7 Apr 1999 09:36:21 +1000
Subject: Embedding python question: PyRun_String only returns None not what I calculate
References: <923433832.14002.0.nnrp-07.9e982a40@news.demon.co.uk>
Message-ID: <7ee5pk$qkm$1@m2.c2.telstra-mm.net.au>
X-UID: 1623                                                  

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.

Mark.

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
>to
>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
None.
>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?







