[C++-sig] cannot import module
Atri, Sunil
Sunil.Atri at spansion.com
Tue Jan 23 08:22:39 CET 2007
Some more info regarding the actual code itself
There are the only two changes I have made to the original source files.
/Modules/Setup.local
# Edit this file for local setup changes
spam spammodule.o
Added the spammodule.c file to the /Modules directory
spammodule.c
#include <Python.h>
static PyObject *
spam_system(PyObject *self, PyObject *args)
{
const char *command;
int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
return Py_BuildValue("i", sts);
}
static PyMethodDef SpamMethods[] = {
{"system", spam_system, METH_VARARGS, "Execute a shell command."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC
initspam(void)
{
(void) Py_InitModule("spam", SpamMethods);
}
Thank you
Sunil
________________________________
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of Atri, Sunil
Sent: Tuesday, January 23, 2007 12:45 AM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] cannot import module
Following the instructions on the documentation page, I placed the
example code "spammodule.c" in the /Modules directory, After compiling I
changed to this directory and started python there. I assume that makes
/Modules my current directory. But I am not sure. Spammodule.o is
present in the /Modules directory.
After browsing around for a while I also used the
sys.path.append("/root/Python-2.5/Modules"). This did not seem to have
any effect, as I got the same result.
/root/Python-2.5 is where I have unzipped the source file. I am using
Linux (Fedora).
Thank you for any assistance you can provide.
Sunil
________________________________
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of Gross, Ashley
Sent: Monday, January 22, 2007 8:55 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] cannot import module
Is the file you're trying to import in your search path or current
directory?
Ashley
________________________________
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of Atri, Sunil
Sent: Monday, January 22, 2007 9:08 PM
To: c++-sig at python.org
Subject: [C++-sig] cannot import module
This is not strictly a C++ question, but I did not find a C forum. I
have trying to compile and install the example given here
http://docs.python.org/ext/simpleExample.html
I was able to compile, but when try to import I get the following
message
>>> import spam
Traceback <most recent call last>:
File "stdin", line 1, in <module>
ImportError: No module named spam
I assume when adding a C function to python this is as simple as it
gets, but I am not having much luck. I am also new to python.
Thanks
Sunil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070123/4ba544d0/attachment.htm>
More information about the Cplusplus-sig
mailing list