runner
runner

Reputation: 601

How to Access a C global variable from Python script

I am new to the python concepts. I have 3 health monitoring Applications Running in intel edison Device. I want to transmit these application result values(int value) to an android App.

So far am able to make a connection over Bluetooth(using SPP profile) with python script. Now I wanted to access those 3 global variables from the 3 different C codes(Application code in intel edison) and send it to Android App.

Someone help me or suggest any methods that are available..

Upvotes: 0

Views: 141

Answers (1)

Manoranjan Padhy
Manoranjan Padhy

Reputation: 113

If the attributes belong to the global scope of a module, then you can use "PyImport_AddModule" to get a handle to the module object. For example, if you wanted to get the value of an integer in the main module named "foobar", you would do the following:

PyObject *m = PyImport_AddModule("__main__");
PyObject *v = PyObject_GetAttrString(m,"foobar");

int foobar = PyInt_AsLong(v);

Py_DECREF(v);

Upvotes: 1

Related Questions