I have an embedded python interpreter in my program. I'd like to export a module with values defined in my program and be able to change them from a python script. e.g.
in c:
int x = 1;
in python:
import embedded
embedded.x = 2
in c:
printf("%d",x);
output:
2
Is this possible or do I have to export functions to ch开发者_如何学Cange anything in c?
There's no need to export functions, but the easiest way to do this would be to use PyModule_GetDict()
with PyDict_GetItemString()
to get the value assigned to the x
attribute.
If you don't want to actively check the value of a PyObject in your C code, I think you need to export functions to modify the representation in C. I'm no expert, but I don't think there's an automatic mapping.
精彩评论