Calling methods in embedded python

Alex Martelli aleax at aleax.it
Wed Nov 13 08:34:15 EST 2002


Krzysztof Wasilewski wrote:
   ...
> PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)
> 
> Return value: New reference.
> Create a new instance of a specific class. The parameters arg and kw are
> used as the positional and keyword parameters to the object's constructor
> ...........................
> 
> What should be passed for kw? I tried an empty tuple, an empty list,
> PyNone and other things, but in vain. The constructor of the classes I
> want to use take either no parameters or a single parameter without a key.
> What should I do?

NULL, 0, or an empty dictionary object, are what you could pass as
kw in this case.  However, you might as well use PyObject_CallObject,
as you say you already do when you know the callable object is a
function: you can use PyObject_CallObject to call ANY callable,
including a class (and when you call a class, the instance is the
call's result, as it would be in Python source).  More generally, I
suggest using the higher-level, abstract functions PyObject_<whatever>
unless you have some specific reason to use "concrete-type", lower
level functions instead.


Alex




More information about the Python-list mailing list