If my_object.MethodName takes no arguments (apart from self) then a
call to mkvalue("()") should be used to create an empty tuple. BTW
mktuple was a typo in the Extending manual -- it's actually called
newtupleobject().
Also note that getattr() returns a "new" object (i.e. you should
DECREF() the result).
If all this doesn't help, I suggest calling print_error() to see what
exception you are getting -- maybeyour Python code raises an exception?
BTW it should be trivial to write a function that does all this for
you -- its signature would be
call_method(object *, char *, char *, ...)
and you would call it like this:
result = call_method(my_object, "MethodName", "()")
the last argument would actually be a mkvalue argument. I guess the
implementation would be (unchecked):
object *call_method(object *inst, char *methodname, char *format, ...)
{
object *method;
object *args;
object *result;
va_list va;
method = getattr(inst, methodname);
if (method == NULL) return NULL;
va_start(va, format);
args = vmkvalue(format, va);
va_end(va);
if (args == NULL) {
DECREF(method);
return NULL;
}
result = call_object(method, args);
DECREF(method);
DECREF(args);
return result;
}
--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>