Extending Python - Understanding Flags...

Redefined Horizons redefined.horizons at gmail.com
Mon Jun 12 23:45:40 EDT 2006


I'm trying to understand the argument flags that are used in the
method table of an extension module written in C.

First let me ask this question about the method table. Is it an C
array named "PyMethodDef"?

Now, onto my questions about the arguments:

[1] I see that even when the Python function we are supplying takes no
arguments, (the argument flag is METH_NOARGS), that we still pass the
C function a reference to "self". Is this "self" actually a pointer to
the section of memory that represents the object in Python that is
calling the method?

[2] What is the difference between "positional" arguments indicated by
the METH_VARARGS argument flag, and "keyword" arguments that are
indicated by the METH_KEYWORDS argument flag? Does one determine the
identity of an argument based on the order or position in which the
arguments are passed to the C function, while the other uses keys in a
dictionary to identify the arguments?

That should be the start of my customization questions... :]

If it is any consolation I hope to take what I learn and put together
a tutorial on expanding Python for those that only have a little
experience with C programming, like myself. I plan to explain
everything like I was teaching a 6-year old. :]

I was just going to put this on a wiki, but is there a way to include
with other Python documentation on an "official" site?

Thanks for the help.

Scott Huey



More information about the Python-list mailing list