I'm trying to use PyDict_Next to iterate over a dict in a way that is
identical to this statement:
for k, v in d.items():
# do stuff with key and value
PyDict_Next has the signature:
int PyDict_Next(PyObject *dictionary, Py_ssize_t *pos, PyObject **key,
PyObject **value)
The basic idea is that the dict uses pos to track which key it is on.
The key is then assigned to the key pointer and the corresponding
value is assigned to the value pointer. It can really help efficiency
because it doesn't involve iterators, tuples, etc.
The most obvious code is the following:
cdef int pos = 0
cdef object key, value
while PyDict_Next(d, &pos, &key, &value):
# do stuff with key and value
However, apparently &python_object is not legal and I'm running into
odd type issues with &pos. Is there a way to get around those
limitations?
-Aaron
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev