creating an object in embedded python

db dbunix at yahoo.com
Wed May 14 18:18:34 EDT 2003


--- Brian Quinlan <brian at sweetapp.com> wrote:
> class = PyObject_GetAttr(module, "Bar")
> inst = PyObject_CallFunctionObjArgs(class, ...,
> NULL)
> /* Or use PyObject_CallFunction */
> retval = PyObject_CallMethod( inst, "mymeth", "i",
> myint );
> /* Make sure that you get rid of the references that
> you don't need */
> 
> Cheers,
> Brian 
> 

Ok, this got me closer, thanks!

Here's what I've got:
module = PyImport_ImportModule( "master" );
// if PyErr_Occurred(), print backtrace
class = PyObject_GetAttrString( module, "master" );
// if PyErr_Occurred, print backtrace
instance = PyObject_CallFunctionObjArgs( class, NULL
);
// if PyErr_Occurred, print backtrace
retval = PyObject_CallMethod( instance, "init", "i",
fooarg );
// if PyErr_Occurred, print backtrace

In master.py, it reads:
class master:
  def init( arg ):
    etc...

The error Im getting is:
TypeError: init() takes exactly 1 argument (2 given)

Im sure this is something simple, Im just having a
hard time groking the API docs to make them useful.
For example, what is the difference between
*callable_object in PyObject_CallObject() and
*callable in PyObject_CallFunction()? What is the
difference in there return values? Does anyone know
where I can find a source example of embedded python
more substantial then the ones in Demo/embed?

db

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list