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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --047d7b343296e5a52504eed3309b Content-Type: text/plain; charset=ISO-8859-1 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 = "" ================================================== #include #include #include 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 --047d7b343296e5a52504eed3309b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
=A0=A0=A0=A0=A0=A0=A0=A0= =A0 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=A0 "/var/tmp"= ; path and trying to fetch objects and functions from python script as belo= w, but
PyImport_ImportModule("test") returning NULL always(instead= adding /var/tmp path to syspath)

Please let me know, how to s= olve this?

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

input =3D "<dummy/>"

=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
#incl= ude <stdio.h>
#include <stdlib.h>
#include <Python.h&g= t;

int main(void)
{
=A0=A0=A0 const char *scriptDirectoryName =3D "/var/tmp";=A0=A0=A0 Py_Initialize();
=A0=A0=A0 PyObject *sysPath =3D PySys_GetObj= ect("path");
=A0=A0=A0 PyObject *path =3D PyString_FromString(= scriptDirectoryName);
=A0=A0=A0 PyList_Insert(sysPath, 0, path);
=A0=A0=A0 PyObject *pModule =3D PyImport_ImportModule("test");=A0=A0=A0 if (pModule =3D=3D NULL) {
=A0=A0=A0=A0=A0=A0=A0 fp =3D fopen= ("/var/tmp/abc.txt", "w");
=A0=A0=A0=A0=A0=A0=A0 fpr= intf(fp, "Fail to search in /var/tmp path");
=A0=A0=A0=A0=A0=A0=A0 fclose(fp);
=A0=A0=A0 } else {
=A0=A0=A0=A0=A0=A0 /* Read input object ... */
=A0=A0 }
<= div>=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0 Py_Finalize();
=A0=A0= =A0 return 0;
}

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

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

Thanks,
Satya


--047d7b343296e5a52504eed3309b--