embedding, PyString_FromString

Lance lbrannma at cablespeed.com
Sun Dec 15 16:53:00 EST 2002


Thanks Martin,

I guess the default namespace, __main__, isn't sufficient for my task. Mark
Lutz says that it's not straightforward to communicate inputs and outputs
with the Python code using PyRun_SimpleString.

Lance

"Martin v. Löwis" <martin at v.loewis.de> wrote in message
news:atir75$6tm$03$1 at news.t-online.com...
> > 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