[pygtk] Diiference between method and a function
John Dennis
jdennis at redhat.com
Thu Jun 14 23:17:49 WST 2007
On Thu, 2007-06-14 at 02:42 -0700, varun_shrivastava wrote:
> hi
>
> i was reading about how to define a wrapper function
> it looks like
>
> static PyObject *
> spam_system(PyObject *self, PyObject *args)
> {
> const char *command;
> int sts;
>
> if (!PyArg_ParseTuple(args, "s", &command))
> return NULL;
> sts = system(command);
> return Py_BuildValue("i", sts);
> }
>
> and then i couldn't understand this line
>
> "The self argument is only used when the C function implements a built-in
> method, not a function. In the example, self will always be a NULL pointer,
> since we are defining a function, not a method."
>
> what is built in method ?
The term built-in is I suspect erroneous in this instance. In python
speak built-in refers to something you do not have to load via an
import, I suspect Guido's language may have been a little sloppy when he
really meant a function or method implemented in C using the CPython
API.
What the Guido (the author) is trying to elucidate is the distinction
between a function and a method. Methods are attributes of a class
object and are bound to a class instance via self. Functions don't exist
within a class, thus they do not have an object to bind to via the self
parameter. Always passing self is a simplification in CPython so one
does not need two interfaces.
--
John Dennis <jdennis at redhat.com>
More information about the pygtk
mailing list