[embed] PyImport_Import cannot find xml.py
Trung Hoang
thoa0025 at mail.usyd.edu.au
Sun Mar 24 15:10:22 EST 2002
I've located the problem down to this. i have a file "xml.py" which has a
function "getProjects()" which i would like to access from c. In the
interpreter i execute the following commands:
Python 2.1.2 (#2, Jan 18 2002, 11:23:35)
[GCC 2.95.2 19991024 (release)] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> modname = "xml"
>>> mod = __import__(modname)
>>> mod
<module 'xml' from 'xml.py'>
>>>
so that says that the module is locatable by the interpreter. but when i
compile and run the following program:
#include <Py/Python.h>
int main (int argc, char *argv[]) {
// declare variables
PyObject *modname = NULL;
PyObject *mod = NULL;
// init
Py_Initialize();
modname = PyString_FromString("xml");
mod = PyImport_Import(modname);
if (mod == NULL) printf("mod is null\n");
Py_XDECREF(mod);
Py_XDECREF(modname);
Py_Exit(0);
}
it prints out "mod is null" meaning it cant find the module.
Does anyone have a working example of Pure Embedding? It's for my personal
private project - for fun, supposedly, well before it was, not my
assignment.
Please :(
Cheeeeeeeeeeers
--
Trung Hoang
Final year Undergraduate of Computer Science and Technology
University of Sydney, Australia.
More information about the Python-list
mailing list