need to extend this C code so that it initiates this python script (python C api)

aregee rahul.nbg at gmail.com
Sat Jul 2 14:17:35 EDT 2011


hi i need help with extending this http://paste.pound-python.org/show/8918/
c code so that it can initiate this python script http://paste.pound-python.org/show/8917/
and export file path here..

btw I tried to run following python code :

#include <python2.3/Python.h> //changed this to python2.7/Python.h
didn't work the I changed it to Python.h
                                              // Error msg : fatal
error: Python.h : no file or directory compilation terminated
                                             //python-dev and
python2.7-dev is already installed.

void process_expression(char* filename,
                        int num,
                        char** exp)
{
    FILE*       exp_file;

    // Initialize a global variable for
    // display of expression results
    PyRun_SimpleString("x = 0");

    // Open and execute the file of
    // functions to be made available
    // to user expressions
    exp_file = fopen(filename, "r");
    PyRun_SimpleFile(exp_file, exp);

    // Iterate through the expressions
    // and execute them
    while(num--) {
        PyRun_SimpleString(*exp++);
        PyRun_SimpleString("print x");
    }
}

int main(int argc, char** argv)
{
    Py_Initialize();

    if(argc != 3) {
        printf("Usage: %s FILENAME EXPRESSION+\n");
        return 1;
    }
    process_expression(argv[1], argc - 1, argv + 2);
    return 0;
}


thanks
aregee
Ar



More information about the Python-list mailing list