Defining Python class methods in C

Alex Martelli aleax at aleax.it
Mon Mar 24 07:55:17 EST 2003


Bryan wrote:
   ...

answering a few outstanding questions even though Bryan has later
managed to solve his problems by using a type rather than a class:

> here's the python script that's being called.  i am not importing the
> context module in the script.  this is an intentional part of the
> design.  but maybe i really do need to import the context module.

No, there is no such need.

>   def start(ctx):
>         print 'context', ctx
> print 'doc', ctx.__doc__, 'end doc'
> print 'path', ctx.get_path(), 'end path'
> 
> 
> 
> here is the output from start.  notice the ?, no doc string, no path

I don't see where you associated any non-None docstring with the ctx.

> string including the 'end path' string.  i'm assuming get_path wasn't
> found and an attribute exception occured.  also, my breakpoint never

The exception is more likely to be due to the METH_NOARGS flag in
your methods table -- should be METH_VARARGS and you should parse
the args tuple to get the 'self' reference to the class isntance.

> stopped in the get_path callback method.  why does python show a ?.
> why doesn't it know that it's from the context module?

You did not set a __module__ string attribute on the class object,
it seems to me.


Alex





More information about the Python-list mailing list