[C++-sig] 'module' object has no attribute 'suma' ?? yes it have!
Nicolas Kowenski
nicolas.kowenski at softogo.com
Tue Dec 7 18:07:08 CET 2004
mi c Source is:
-------------------------------------------------------------------------------------------------------------------
/#include </home/dev/Python/Python-2.4/Include/Python.h>
int num=0;
int suma(int b)
{
printf("sumando....");
num+=b;
return (num);
}
int resta(int b)
{
printf("restando...");
num-=b;
return (num);
}
int setnum(int b)
{
printf("seteando ...");
num=b;
return (num);
}
int traenum()
{
return (num);
}
static PyObject *test_suma(PyObject *self, PyObject *args)
{
int b;
int sts;
if (!PyArg_ParseTuple(args, "i",&b))
{
puts("dio nulll el traductor python-c, sumador");
return NULL;
}
sts = suma(b);
return Py_BuildValue("i", sts);
}
/*******************************************************************************************/
static PyObject *test_resta(PyObject *self, PyObject *args)
{
int b;
int sts;
if (!PyArg_ParseTuple(args, "i", &b))
return NULL;
sts = resta(b);
return Py_BuildValue("i", sts);
}
/*******************************************************************************************/
static PyObject *test_setnum(PyObject *self, PyObject *args)
{
int b;
int sts;
if (!PyArg_ParseTuple(args, "i", &b))
return NULL;
sts = setnum(b);
return Py_BuildValue("i", sts);
}
/*******************************************************************************************/
static PyObject *test_traenum(PyObject *self, PyObject *args)
{
int sts;
sts = traenum();
return Py_BuildValue("i", sts);
}
/*******************************************************************************************/
static PyMethodDef TestMeth[] = {
{"suma", test_suma, METH_VARARGS,"Suma un numero"},
{"resta", test_resta, METH_VARARGS,"Resta un numero"},
{"setnum", test_setnum, METH_VARARGS,"Setea el numero"},
{"traenum", test_traenum, METH_NOARGS,"Trae el numero"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
/*******************************************************************************************/
PyMODINIT_FUNC inittest(void)
{
(void) Py_InitModule("test", TestMeth);
}
int main(int argc, char *argv[])
{
/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(argv[0]);
/* Initialize the Python interpreter. Required. */
Py_Initialize();
/* Add a static module */
inittest();
}/
-------------------------------------------------------------------------------------------------------------------
/
Compiled with Clases.py:
from distutils.core import setup, Extension
module2 = Extension('test',
sources = ['CLASES.c'])
setup (name = 'PackageName',
version = '2.0',
description = 'probando claes en piton',
ext_modules = [module2])
-----------------------------------------------------------------------------------------------------------------
/then:
>>> import test
>>> test.suma(1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'suma'
>>>
Thankz bye!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20041207/a6a1c1bd/attachment.htm>
More information about the Cplusplus-sig
mailing list