On Mar 20, 11:03 am, "Martin v. Löwis" <mar...@v.loewis.de> wrote: > > Any idea on why this is happening? > > Can you provide a complete example? Your code looks correct, and should > just work. > > How do you know the result contains only 't' (i.e. how do you know it > does not contain 'e', 's', 't')? > > Regards, > Martin
Hi Martin, Here is the code: unicodeTest.c #include<Python.h> static PyObject *unicode_helper(PyObject *self,PyObject *args){ PyObject *sampleObj = NULL; Py_UNICODE *sample = NULL; if (!PyArg_ParseTuple(args, "O", &sampleObj)){ return NULL; } // Explicitly convert it to unicode and get Py_UNICODE value sampleObj = PyUnicode_FromObject(sampleObj); sample = PyUnicode_AS_UNICODE(sampleObj); wprintf(L"database value after unicode conversion is : %s\n", sample); return Py_BuildValue(""); } static PyMethodDef funcs[]={{"unicodeTest",(PyCFunction) unicode_helper,METH_VARARGS,"test ucs2, ucs4"},{NULL}}; void initunicodeTest(void){ Py_InitModule3("unicodeTest",funcs,""); } When i install this unicodeTest on python ucs2 wprintf prints whatever is passed eg import unicodeTest unicodeTest.unicodeTest("hello world") database value after unicode conversion is : hello world but it prints the following on ucs4 configured python: database value after unicode conversion is : h Regards, Abhigyan -- http://mail.python.org/mailman/listinfo/python-list