Embedded Python implementation

Evan tagith1394 at hotmail.com
Sat Sep 7 12:02:48 EDT 2002


Chris Liechti wrote:
> Evan <tagith1394 at hotmail.com> wrote in 
> news:MAfe9.266658$v53.14092531 at news3.calgary.shaw.ca:
> 
> 
>>Hello,
>>
>>I am currently trying to embed Python in an application I am writing, 
>>and all is going well, except for one inexplicable bug..
>>
>>When I pass a variable (pointer to a string) to PyRun_String, it will 
>>always error on line 2, character 5.. regardless of what is actually on 
>>the line in that spot (for that matter, even if there is no line 2)..
> 
> 
> that sounds as you woul not pass the pointer to a string but to something 
> else...
> 
> 
>>The script works perfectly when I place it in a file, and use 
>>PyRun_File, and it also works perfectly when I place the string in 
>>quotations, and pass it to PyRun_String directly inside the C code..
>>
>>The C code in question is as follows:
>>if ( PyRun_String( com_list, Py_file_input, pGlobals, pLocals ) == NULL )
>>         PyErr_Print();
> 
> 
> i think that sould work when com_list is a "char *", say:
> char * com_list = "print hello\n";
>  
> 
>>I am confident the problem is not with pGlobals or pLocals, as those 
>>arguments are used with PyRun_File, as well as with the quoted string..
> 
> 
> chris

I have inserted a small amount of C to print the contents of com_list, 
right before the PyRun_String, here is the complete output (*** marks 
beginning and end of the script)

  ***
112 (p) 114 (r) 105 (i) 110 (n) 116 (t) 32 ( ) 34 (") 104 (h) 101 (e) 
108 (l) 108 (l) 111 (o) 34 (") 10 (
)  ***
      File "<string>", line 2

        ^
SyntaxError: invalid syntax




More information about the Python-list mailing list