using the C API to access objects derived from builtin classes

Stefan Seefeld seefeld at sympatico.ca
Tue May 18 20:13:55 EDT 2004


Thomas Heller wrote:

>>Replacing 'PyDict_SetItem' by 'PyObject_SetItem' did the trick.
>>I guess 'PyDict_SetItem' is a shortcut to circumvent the lengthy
>>method lookup. Fair enough, but the python C API documentation could
>>be a bit more clear about that...
> 
> 
> I would guess the *real* problem is that you are ignoring the return
> value of PyDict_SetItem (or whatever api you use).  In this case you get
> weird errors afterwards.

good shot ! Well, what the 'real' problem is is probably a matter
of perspective, but you are quite right in that I failed to check
a return value (and associated exception) so python's own code
eventually bumped into it in an unrelated context.

But back to the other issue: isn't there any text that explains
when I should be using PyDict_GetItem and when PyObject_GetItem
and what they are doing byhind the scene ?

Regards,
		Stefan




More information about the Python-list mailing list