Defining Python class methods in C

Alex Martelli aleax at aleax.it
Sun Mar 23 05:54:54 EST 2003


Bryan wrote:

> i found one of my problems:
> 
> i was using METH_NOARGS for get_path.  when i changed to METH_VARARGS
> my callback got called.  but the self variable in context_get_path is
> NULL. so i can't get to the variables i stored in the context_object
> from the __init__ call.

You need to pass as your callback the *BOUND method* get_path of some
instance of your class.  When you do so, the "self" will be the first
ordinary argument to the underlying function whenever the bound
method is called, so you can PyArg_ParseTuple it.  Again, you're
falling afoul of the still-surviving type/class split, and again
I think you'd be better advise to implement a type, not a class.


Alex





More information about the Python-list mailing list