Problems with dict and C API

Alex Martelli aleaxit at yahoo.com
Tue Sep 7 05:48:16 EDT 2004


Matjaz <surfmatj at email.si> wrote:

> Alex,
> 
> thank you for this valuable piece of information. I will
> indeed try to use mapping protocol as much as possible.
> However, I am curious of the following: were the
> functions for setting/getting items (should be PyMapping_SetItem
> and PyMapping_GetItem, like that for object and dictionaries)
> left out on purpose, because there exist
> only "string" versions PyMapping_SetItemString and
> PyMapping_GetItemString?

No, you're just still looking at a too-specific level -- think abstract!

PyObject_SetItem and PyObject_GetItem are the API functions you're
looking for; there is no PyMapping_SetItem because it would just be a
total duplicate of PyObject_SetItem, just about.  The ...String
convenience functions are there because using a string key is such a
frequent task on mappings specifically, not on objects in general.  But
indexing _IS_ frequent on objects in general, so it's supported at that
level.


Alex



More information about the Python-list mailing list