12.3.1 Dictionary Objects

PyDictObject
This subtype of PyObject represents a Python dictionary object.

PyTypeObject PyDict_Type
This instance of PyTypeObject represents the Python dictionary type.

int PyDict_Check (PyObject *p)
returns true if it's argument is a PyDictObject

PyDictObject * PyDict_New ()
returns a new empty dictionary.

void PyDict_Clear (PyDictObject *p)
empties an existing dictionary and deletes it.

int PyDict_SetItem (PyDictObject *p, PyObject *key, PyObject *val)
inserts value into the dictionary with a key of key. Both key and value should be PyObjects, and key should be hashable.

int PyDict_SetItemString (PyDictObject *p, char *key, PyObject *val)
inserts value into the dictionary using key as a key. key should be a char *

int PyDict_DelItem (PyDictObject *p, PyObject *key)
removes the entry in dictionary p with key key. key is a PyObject.

int PyDict_DelItemString (PyDictObject *p, char *key)
removes the entry in dictionary p which has a key specified by the char *key.

PyObject * PyDict_GetItem (PyDictObject *p, PyObject *key)
returns the object from dictionary p which has a key key.

PyObject * PyDict_GetItemString (PyDictObject *p, char *key)
does the same, but key is specified as a char *, rather than a PyObject *.

PyListObject * PyDict_Items (PyDictObject *p)
returns a PyListObject containing all the items from the dictionary, as in the mapping method items() (see the Reference Guide)

PyListObject * PyDict_Keys (PyDictObject *p)
returns a PyListObject containing all the keys from the dictionary, as in the mapping method keys() (see the Reference Guide)

PyListObject * PyDict_Values (PyDictObject *p)
returns a PyListObject containing all the values from the dictionary, as in the mapping method values() (see the Reference Guide)

int PyDict_Size (PyDictObject *p)
returns the number of items in the dictionary.

int PyDict_Next (PyDictObject *p, int ppos, PyObject **pkey, PyObject **pvalue)

guido@CNRI.Reston.Va.US