C API - tp_getattro and tp_methods

André Malo auch-ich-m at g-kein-spam.com
Mon Apr 24 16:40:35 EDT 2006


* williams.jasonscott at gmail.com wrote:

> I'm using a tp_getattro function to call into a C library and get
> values the the lib keeps track of.  This works:
[...]

> Thats great but I also want to expose some instance methods and I'm
> having trouble.
> 
> But when I set tp_methods nothing shows up?  If I unset tp_getattro I
> can use my methods.  I'm not understanding the relationship between the
> two, tp_methods and tp_getattro.  Could someone point me in the right
> direction?

tp_getattro is like defining __getattribute__, i.e. it gets called on every
attribute read access. You can use PyObject_GenericGetAttr inside the
function to find predefined attributes before applying your own rules.

nd
-- 
"Die Untergeschosse der Sempergalerie bleiben währenddessen aus
 statistischen Gründen geflutet." -- Spiegel Online



More information about the Python-list mailing list