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


Groups > comp.lang.python > #62928

PyImport_ImportModule(..) returns NULL

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <pythonsatya@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; 'sys': 0.07; '#include': 0.09; 'skip:/ 10': 0.09; 'python': 0.11; "api's": 0.16; 'fetch': 0.16; '\xa0\xa0\xa0\xa0\xa0\xa0': 0.16; 'thanks,': 0.17; 'trying': 0.19; 'skip:f 30': 0.19; 'skip:p 40': 0.19; 'input': 0.22; 'import': 0.22; 'this?': 0.23; 'char': 0.24; 'script': 0.25; 'to:2**1': 0.27; 'skip:p 30': 0.29; 'to:no real name:2**1': 0.29; 'message-id:@mail.gmail.com': 0.30; 'embedding': 0.31; 'null)': 0.31; 'file': 0.32; 'skip:# 10': 0.33; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'returning': 0.36; 'hi,': 0.36; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'skip:& 20': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'read': 0.60; 'solve': 0.60; 'new': 0.61; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'const': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=UEuRwg31uci/xM09A/tkOAsKwa4Md8OWDE9Xi8BxFA8=; b=A6XPtLQ3V268G2fEWLqkeVUIPZ2Zfq7VSZvmORLjl2V1P9ATN0hY1yLo/S2c4nj7Xp GVxqj2/EOQcbSnS0BByWRmSPYcIuP9kiV0F+THlJatHB7HswHAgDqrpaTEuM7D2Fvy4I Qy/989ahmAdeF42dcPDGmxj1QPS6C1+ZcOcDJ118droj+yKSmsypM3oEldQIQrp+xQQw MAC2f9WCvGYPTI6CEi1f1Cz2iYGkpPWeKvrwlHyERg38ObDK5dkA2/uod+szGCG0/Onr Sx5KlADVy043/oA1SY6d22m7uD3blCoYNxkqNhqLRlZ0Y9sA8SpeRYa0qx8miLJlRLKZ SSPw==
MIME-Version 1.0
X-Received by 10.220.139.136 with SMTP id e8mr5558067vcu.34.1388490732707; Tue, 31 Dec 2013 03:52:12 -0800 (PST)
Date Tue, 31 Dec 2013 17:22:12 +0530
Subject PyImport_ImportModule(..) returns NULL
From python satya <pythonsatya@gmail.com>
To python-list@python.org, pythonsatya@gmail.com
Content-Type multipart/alternative; boundary=047d7b343296e5a52504eed3309b
X-Mailman-Approved-At Tue, 31 Dec 2013 15:18:03 +0100
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4754.1388499484.18130.python-list@python.org> (permalink)
Lines 90
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1388499484 news.xs4all.nl 2876 [2001:888:2000:d::a6]:60876
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62928

Show key headers only | View raw


[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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web