Where does Python save the result of the last operation?
For example, If the last operation was math.sqrt(9)
, where does Python save the value 3.0?
Or if 开发者_JAVA技巧the last operation was "hello " + "world!"
, where is the value 'hello world!'
saved?
I want to approach this from a C program (using Python's C API) and pass this value to a char*
variable.
Python itself does not save the result of the last operation. The Python REPL saves the last result in _
, but you would not be using the REPL in this situation.
It doesn't.
It sounds like you want to call Python code from C, and use the result in the rest of the C code.
What you do is write a function in the Python code, and use its return value. It will be passed back as a PyObject*
from the C API function that calls the Python function.
精彩评论