#include <stdio.h> #include <stdlib.h> #include <python.h> int main() { char *k = (char*)calloc(100,1); strncpy(k,"iloveyou", 8);
printf("Hello world!\n"); printf("%s\n",k); free(k); printf("%c\n",k[0]); sprintf(k,"%s","china"); printf("%s\n",k); free(k); k = NULL;
PyObject *a = "4543534"; const char *bb = "fsdfdfs"; PyObject *b = NULL;
if(PyString_Check(a)) printf("ok\n"); else printf("no\n");
printf("%s\n",a); b = PyString_FromString(bb); printf("b:%s\n",b);
PyObject *q; q = PyList_New(3); PyList_SetItem(q,0,PyLong_FromLong(1L)); PyList_SetItem(q,1,PyLong_FromLong(2L)); PyList_SetItem(q,2,PyString_FromString("three")); PyObject *p; p = PyList_GetItem(q,2); char *op = PyString_AsString(p); printf("pitem:%s\n",op); int n = PyString_Size(p); printf("length:%d\n",n);
PyStringObject* s = PyString_FromString("qianshou"); if(PyString_Check(s)) printf("good\n"); else printf("bad\n");
PyString_Concat(PyString_FromString("qq"),s); printf("last:%s\n",PyString_AsString(s));
return 0; }
|