Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62928 > unrolled thread

PyImport_ImportModule(..) returns NULL

Started bypython satya <pythonsatya@gmail.com>
First post2013-12-31 17:22 +0530
Last post2013-12-31 17:22 +0530
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  PyImport_ImportModule(..) returns NULL python satya <pythonsatya@gmail.com> - 2013-12-31 17:22 +0530

#62928 — PyImport_ImportModule(..) returns NULL

Frompython satya <pythonsatya@gmail.com>
Date2013-12-31 17:22 +0530
SubjectPyImport_ImportModule(..) returns NULL
Message-ID<mailman.4754.1388499484.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

Hi,
          I am new to python, am trying to use embedding python API's in
C,as below

I have my python file test.py in  "/var/tmp" path and trying to fetch
objects and functions from python script as below, but
PyImport_ImportModule("test") returning NULL always(instead adding /var/tmp
path to syspath)

Please let me know, how to solve this?

$% more /var/tmp/test.py
#!/usr/bin/python

import sys

input = "<dummy/>"

==================================================
#include <stdio.h>
#include <stdlib.h>
#include <Python.h>

int main(void)
{
    const char *scriptDirectoryName = "/var/tmp";
    Py_Initialize();
    PyObject *sysPath = PySys_GetObject("path");
    PyObject *path = PyString_FromString(scriptDirectoryName);
    PyList_Insert(sysPath, 0, path);
    PyObject *pModule = PyImport_ImportModule("test");
    if (pModule == NULL) {
        fp = fopen("/var/tmp/abc.txt", "w");
        fprintf(fp, "Fail to search in /var/tmp path");
        fclose(fp);
    } else {
       /* Read input object ... */
   }

    Py_Finalize();
    return 0;
}

====================================================

$% more /var/tmp/abc.txt
Fail to search in /var/tmp path

Thanks,
Satya

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web