module is in the folder - what am i doing wrong??

Trung Hoang thoa0025 at mail.usyd.edu.au
Sun Mar 24 06:56:55 EST 2002


Thanks for your reply Jim,

i have a file "xml.py" and it has a function named "getProjects()" and i
simply wish to access it from c. i have the source....

#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);
}

but when i try to run it, it prints "mod is null", meaning it cant find the
module. but the module is named "xml.py" and is in the current folder!! what
am i doing wrong???

i dont see why it is so hard. it's just that ive fallen in a small hole
(idom).. just one of those things when you learn a new language... i just
need a little help. im sure someone knows :(

ive thought of using exec, but this way is far more elegant.. so i've read.
but not proven.

Please HELP!
Cheers
Trung Hoang
Final year Undergraduate of Computer Science and Technology
University of Sydney, Australia.





More information about the Python-list mailing list