Python C Embedded ! Attribute Error
Miki
miki.tebeka at gmail.com
Fri Jul 20 14:30:42 EDT 2007
Hello,
> I am using the below C code so that i can embed a Python Code and
> get input from a python function and use it in C code .
>
> Below is the C Code
[snipped]
> I am getting error
>
> AttributeError: 'module' object has no attribute 'print'
> Cannot find function "print"
How do you run your program (I suspect with 'pr pr print 1', should be
'pr pr pr 1').
FWIW, the following simplified program works:
#include <Python.h>
int
main(int argc, char *argv[])
{
PyObject *modname, *module, *args, *value, *func;
Py_Initialize();
PyRun_SimpleString("import sys; sys.path.append(\".\")");
modname = PyString_FromString("pr");
module = PyImport_Import(modname);
Py_DECREF(modname);
if (NULL == module) {
fprintf(stderr, "error: can't load\n");
Py_Finalize();
return 1;
}
func = PyObject_GetAttrString(module, "pr");
args = PyTuple_New(1);
value = PyLong_FromLong(10);
PyTuple_SetItem(args, 0, value);
PyObject_CallObject(func, args);
Py_Finalize();
return 0;
}
HTH,
--
Miki <miki.tebeka at gmail.com>
http://pythonwise.blogspot.com
More information about the Python-list
mailing list