General questions about embedding Python.

amit amit at digitalpeers.com
Mon Jul 4 01:43:30 CEST 2005


Hello,

I am currently studying how to embedd python. I am developing a 
graphical C++ application. My goal is to embedd python script that will 
control some kind of animation.
 I have some questions about python embedding:

1) Is there a good text book or other resource on embedding/extending? 
(I find it hard to learn only by the tutorial and C/Python API from the 
python.org site)

2) I have found that there are many ways to embedd a script:
       PyEvel_EvalCode()
       PyRun_SimpleFile()
       PyObject_CallObject()
    What are the cons and pros of using each of them?

3) Is there a problem with the PyRun_SimpleFile(). I am trying to run 
the following code:

const char *SCRIPT_NAME = "C:\\test_script.py";

int _tmain(int argc, _TCHAR* argv[])
{
    Py_Initialize();

    FILE *script_file;
    script_file = fopen(SCRIPT_NAME, "r");
   
    if (script_file != NULL)
        PyRun_SimpleFile(script_file, SCRIPT_NAME);

    Py_Finalize();


    return 0;
}

The python script has only one line: 'print "hello"'

I build it with Python2.3 libraries. When I try to run the code I get 
access violation.

4) What is the correct way to handle/catch python exceptions in the 
embedding Python code?

Forgive me if I have asked too many questions in one eMail, it is 
becuase I don't really know where to start learning this subject from.

Thanks
  Amit




More information about the Python-list mailing list