importing in Dictionairy

Chris Liechti cliechti at gmx.net
Fri Feb 1 13:56:02 EST 2002


"Arno Baan" <a.baan at fokkerspace.nl> wrote in
news:01c1ab1c$13174290$528e4991 at pc1490: 

> I really don't understand this, please help me.
> I've got the following problem, illustrated by the example code 
below.
> When I embed the python interpreter and I want to compile and run 
some
> simple python code. 
> It stops when I try to import a module.
> When I run the same code using PyRun_SimpleString it works the way I 
> expect it to. But because I need to retrieve computed values I need 
> the dict object.
> Can someone explain to me why I can't import modules when I use the 
> dict object??
> 
> #include<Python.h>
> #include<compile.h>
> #include<eval.h>
> #include<string>
> 
> void main(int argc, char * argv[]){
> PyObject * pcode, * pdict, * pmod;
> 
> string code1 = "print 'importing string'\nimport string\nprint 
'done'";
> Py_Initialize();
> 
> pdict = PyDict_New();
> pcode = Py_CompileString((char *)code1.c_str(), "<embed>",
> Py_file_input); 
> 
> (void) PyEval_EvalCode((PyCodeObject *)pcode, pdict, pdict);
> }
> 
> Output:
> importing string
> 
> Thanks a lot,
> 
> arno
> 

just a guess:
don't you need a "\n" at the end of the string above?

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list