[Python-Dev] Calling Methods from Pythons C API with Keywords
hrvoje.niksic at avl.com
Wed Jun 20 13:38:49 CEST 2007
[ Note that this discussion, except maybe for the suggestion to add a
simpler way to call a method with keyword args, is off-topic to
On Wed, 2007-06-20 at 20:17 +1000, Campbell Barton wrote:
> I dont think I can use PyObject_GetAttrString because the subtype would
> return a reference to this function - rather then the lists original
> function, Id need an instance of a list and dont have one at that point.
Note that PyList_Type is a full-fledged PyObject, so
PyObject_GetAttrString works on it just fine. Of course, you would also
need to add the "self" argument before the keywords, but that's a
trivial change to the function.
Calling PyObject_GetAttrString feels cleaner than accessing tp_dict
directly, and most importantly call_method as written delegates creation
of the dictionaty to Py_BuildValue.
More information about the Python-Dev