[Python-Dev] Calling Methods from Pythons C API with Keywords
cbarton at metavr.com
Tue Jun 19 16:21:32 CEST 2007
My first post on this list so I hope this is the right place to post and
Im rewriting parts of the Blender3D python API that has got a bit old
and needs an update.
Im making a PyList subtype with the C/Python API, this involves
intercepting calls to standard list methods to make sure Blenders array
data is in Sync with the list's data.
Iv got it working for tp_as_sequence, tp_as_mapping, iter and dealloc
etc but methods are a problem.
I want to add my own call's before and after PyLists standard functions
but have a proplem with functons that use keywords and have no API
For example, I cant use the API's PyList_Sort because that dosnt support
ls.sort(key=lambda a: a.foo))
And the Problem with PyObject_CallMethod is that it dosnt accept keywords.
PyObject_CallMethod((PyObject *)mylist, "sort", "O", args);
Looking at abstract.c, PyObject_CallMethod uses call_function_tail,
which calls "PyObject_Call(callable, args, NULL);" - so Its not
currently possible with PyObject_CallMethod.
But I cant find any way to do this in a few lines.
I could use PyEval_CallObjectWithKeywords but that would mean Id need to
get the method from the list manually which Ill look into, but unless Im
missing something here, it seems PyObject_CallMethodWithKeywords would
be a nice addition to the Python API that cant be done in a straight
forward way at the moment.
More information about the Python-Dev