在“扩展和嵌入python解释器”中的文档之后,我创建了一个vc项目,并成功创建了一个名为“spam_d.dll”的dll文件。
主代码是
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);
}
然后我在python中键入以下命令:
进口垃圾邮件
〔参考文献39003〕
垃圾邮件系统(“pwd”)
/svn/python/pcbuild
零
〔参考文献39005〕
它看起来工作正常。
但当我将dll名称从spam_d.pyd重命名为spam.pyd时。python找不到模块。
>>> import spam
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named spam
[39005 refs]
从第一种情况看,python可以正确地设置“import spam”和“spam_d.pyd”之间的关系。
python如何知道“spam”模块是“spam_d.pyd”,而不是“spam.pyd”?
有没有文件提到过。