C-API, tp_dictoffset vs tp_members

Ulrich Eckhardt doomster at knuut.de
Tue Jul 21 07:16:10 CEST 2009


When would I use PyObject_SetAttrString/tp_dictoffset instead of tp_members? 

I have a predefined set of members, some of which are optional. The problem 
I had with an embedded dictionary was that I can't see its elements using 
"dir()". Now I just converted to using tp_members, and it still seems to 
work correctly for the cases I tested. Even better, I can declare the fields 
as read-only then and add doc-strings. So, I wonder, what made the original 
author[2] use tp_dictoffset instead? 

In case you wonder, I'm looking at the Python bindings for GDB[1], file 
gdb/python/python-type.c, struct field_object.



[1] http://sourceware.org/gdb/wiki/PythonGdb
[2] Yes I could ask them, but I'd like to get an understanding of the pros 
and cons.

More information about the Python-list mailing list