<div>Hi</div>
<div>thanks for your response</div>
<div>in the last piece of c code i want to know how do i pass structure into python function in c. I have tried to call a python function which takes string as parameter. </div>
<div> </div>
<div>i have passed string parameter as : </div>
<div><font color="#000000"><font size="2"><font size="2">const</font></font><font size="2"> </font><font size="2"><font size="2">char</font></font><font size="2"> *str_pArgs = </font><font size="2"><font size="2">"hello"</font></font><font size="2">;</font></font></div>
<div><font color="#000000"><font size="2"><font size="2">pArgs = PyTuple_New(1);</font></font></font></div>
<div><font color="#000000"><font size="2"><font size="2">pValue = PyString_FromString(str_pArgs);</font></font></font></div>
<div><font color="#000000"><font size="2"><font size="2">PyTuple_SetItem(pArgs, 0,pValue);</font></font></font></div>
<div><font size="2">pValue = PyObject_CallObject(pFunc, pArgs);</font></div>
<div> </div>
<div>similarly how do i convert this structure for python function argument.</div>
<div> </div>
<div>->pArgs = e //******************logic to assign struct employee into pArgs</div>
<div> </div>
<div>regards</div>
<div>ah<br><br></div>
<div class="gmail_quote">On Tue, Jan 12, 2010 at 5:33 PM, a h <span dir="ltr"><<a href="mailto:ah.kode@gmail.com">ah.kode@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Hi</div>
<div>I have witten C code which call a function defined in python, passing an structure, but couldn't know how to pass c structure into a python function(data conversion) and how to write python script function which takes an c structure and fill value into it (commented portion)</div>
<div> </div>
<div>I have looked at struct module but couldn't understand that how it works for below.</div>
<div> </div>
<div>typedef struct employee<br>{<br> char emp_name[10];<br> int emp_ID;<br>}emp;</div>
<div> </div>
<div>int main()<br>{<br>emp e = {0};<br>Pyobject *pName, *pModule, *pFunc, *pArgs,*pValue;</div>
<div>Py_Initialize();<br>pName = PyString_FromString("test");<br>pModule = PyImport_Import(pName);<br>Py_DECREF(pName);</div>
<div>if (pModule != NULL)<br>{<br>pFunc = PyObject_GetAttrString(pModule, "testStruct");<br>if(pFunc && PyCallable_Check(pFunc))<br>{<br>pArgs = e //******************logic to assign struct employee into pArgs<br>
pValue = PyObject_CallObject(pFunc, pArgs);<br>}<br>}<br>Py_DECREF(pValue);<br>Py_DECREF(pModule);<br>Py_Finalize();<br>return 0;<br>}</div>
<div> </div>
<div>and now python script test.py<br>def testStruct(): # **** need any parameter will be specify<br>#**** assign value into the cStructure<br>f=open(filename)</div>
<div>f.write(cStructure.Value) # **** value to write in file</div>
<div> </div>
<div>Thanks in advance</div>
<div>regards</div>
<div>ah</div></blockquote></div><br>