implementing module functions==object methods in extension
Harald Kirsch
kirschh at lionbioscience.com
Fri May 4 05:27:30 EDT 2001
In the python-2.0 distribution I find that string.join() seems to be
implemented as
def string.join(words, sep = ' '):
return sep.join(words)
I wonder if this is mostly historical or if it is still the preferred
way to allow object methods to be called as module functions. I would
rather have expected a pure C solution. Consider for example an object
method with one integer parameter:
static PyObject*
someObjectMethod(PyObject* self, PyObject *args)
{
int i;
if( !self ) {
/* we were in fact called as a module function, try to retrieve
a matching object from args */
if( !PyArg_ParseTuple(args, "o!i", SomeObjectType, &self, &i) )
return NULL;
} else {
/* we were obviously called as an object method so args should
only have the int value. */
if( !PyArg_ParseTuple(args, "i", &i) )
return NULL;
}
}
I'll try this in a minute to find out how it works, but assuming that
it will, I wonder why e.g. string.join() is not implemented that way?
Harald Kirsch
--
----------------+------------------------------------------------------
Harald Kirsch | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172 | -- Paul Erdös
*** Please do not send me copies of your posts. ***
More information about the Python-list
mailing list