making attributes visible in C wrapper

John Machin machin_john_888 at hotmail.com
Fri May 25 01:42:05 EDT 2001


Ahmed Bouferguene <ahmed.bouferguene at Newlix.com> wrote in message news:<3B0D69BC.F116B37A at Newlix.com>...
> Greetings,
> 
> Can anybody tell me what is the way to make visible the attributes of a
> new type in a C wrapper.
> 
> I have a module x in which I define a new type Y.
> I have defined Y_getattr( ) but so far I was only able to make the
> functions operating on Y visible (by dir on an instance of Y) by
> Py_FindMethod( ).
> 
> 
> What is the general way to make methods and other attributes visible by
> dir.

If you don't already have a copy of the source for the version of
Python that you are using, get it --- most of the standard types are
implemented in C modules. An "extension" module is called an extension
because *you* write it to extend Python; there is no structural
difference. So the python source is a good place to look to see how
things are done, especially in the objects and modules directories.

This may answer your specific question, at least as far as non-method
attributes are concerned:

Look at the implementation of the getattr and setattr slots in (for
example) objects/fileobject.c; key items are the use of PyMember_Get()
and PyMember_Set() functions, and the memberlist struct which is
defined in structmember.h ... is this what you wanted to know?



More information about the Python-list mailing list