Embedded Python Question2

Christian Lemer Christian.Lemer at usrconsult.be
Tue May 25 03:55:12 EDT 1999


Hi, 


My first question is about documentation. The Chapter 2 of Python/C API
Reference Manual "The Very High Level Layer" is very concise. It only
gives the prototypes of some functions but nothing else:

--------------------------------------------------------------------------------
int PyRun_AnyFile (FILE *fp, char *filename) 
int PyRun_SimpleString (char *command) 
int PyRun_SimpleFile (FILE *fp, char *filename) 
int PyRun_InteractiveOne (FILE *fp, char *filename) 
int PyRun_InteractiveLoop (FILE *fp, char *filename) 
struct _node* PyParser_SimpleParseString (char *str, int start) 
struct _node* PyParser_SimpleParseFile (FILE *fp, char *filename, int
start) 
PyObject* PyRun_String (char *str, int start, PyObject *globals,
PyObject *locals) 
PyObject* PyRun_File (FILE *fp, char *filename, int start, PyObject
*globals, PyObject *locals) 
PyObject* Py_CompileString (char *str, char *filename, int start) 
--------------------------------------------------------------------------------

Where can I find more information about it, more specifically on
PyRun_String (what are globals and locals,...)


 

My second question is more practical and may be related with the
previous one:

I try to embed python in a C application to be able to use the COM
interface (specifically to interact with Excel using the module
generated by makepy.py).

I want to generate a report in Excel from datas available in my C
program.

I inteded to generate some PyObject matrices (List of List) with
PyList_New, PyList_Append....

i.e:
	PyObject *mat;
        mat = PyList_New(0);
        for(ilin=0; ilin<=nLines; ilin++) {
                line = PyList_New(0);
                for(icol=0; icol<=nCols; icol++) {
                        cell = PyInt_FromLong(ilin*nCols+icol);
                        PyList_Append(line, cell);
                }
                PyList_Append(mat, line);
                cell  = PyInt_FromLong(ilin);
        }

Then I would like to send this to excel, but the only way I found is to
use PyRun_SimpleString..

Something like:

        PyRun_SimpleString("import Excel8\n");
        PyRun_SimpleString("o = Excel8.Application()\n");
        PyRun_SimpleString("o.Workbooks.Add()\n");
        PyRun_SimpleString("w = o.Workbooks(1)\n");
        PyRun_SimpleString("s = w.Worksheets(1)\n");
        PyRun_SimpleString("r =
s.Range(s.Cells(1,1),s.Cells(len(mat),len(mat[0])))\n");
        PyRun_SimpleString("r.Formula = mat\n");
        PyRun_SimpleString("o.Visible = 1\n");
        Py_Exit(0);

Is there any way to "register" my PyObject mat variable in the
interpreter session..

Thanks in advance for your help.

Chris.

-- 
Christian LEMER                                    tel +32.10.65.44.11
UsrConsult S.P.R.L                                 fax +32.10.65.44.10
rue Margot, 37	                              http://www.usrconsult.be
B-1457 Nil St Vincent             mailto:Christian.Lemer at usrconsult.be




More information about the Python-list mailing list