The Documentation for PyList_GetSlice could provide example usage

For example if someone wanted to do the equivalent of the python expression [:1] they would most likely do PyList_GetSlice(splittedContent, 0, 1). But what about when they want [1:]? As such I feel like an example for that case should be added to the docs.

In my case splittedContent is a string object that got split using PyUnicode_Splitlines.

In my case I am trying to implement csv processing inside of a c extension and so I am using the api for slitting the lines, doing the slices, and then using the csv module from that.

1 Like

Well, that’s equivalent to [1:len(splittedContent)], right? So at least you can translate that.

But more generally, I would say that documentation page should explain how index parameters of type Py_ssize_t are interpreted. Are negative values supported with Python semantics, or do they have some other special meaning?

Return a list of the objects in list containing the objects between low and high . Return NULL and set an exception if unsuccessful. Analogous to list[low:high] . Indexing from the end of the list is not supported.

It looks like this is already documented.

I thought it was [n:len(obj)-n]. But that might be correct.

No, the second number is a (one-past-the-)endpoint, not a count. (Also, slices don’t raise exceptions just because the endpoints are out of range; they just skip the “missing” elements.)