embedding, PyString_FromString

Martin v. Löwis martin at v.loewis.de
Sun Dec 15 16:12:12 EST 2002


> int main(int argc, char* argv[])
>  {
>   Py_Initialize();
>   PyObject *pstr1;
>   char pstr[20];
>   strcpy(pstr,"recode");
>   pstr1 = PyString_FromString(pstr);
>   PyRun_SimpleString("print 'hello '+pstr1");
>   return 0;
>  }

Declaring a Variable in C with the C identifier pstr1 doesn't
magically make such a variable appear in Python. You need to
pick some namespace to evaluate this statement in, and then you
need to bind the variable in that namespace.

Since the variable pstr1 is undefined in Python, you get the 
NameError.

Regards,
Martin




More information about the Python-list mailing list