Stefan Behnel wrote:
> This would be a rather straight forward thing to support:
>
>       cdef char* s = ...
>       py_s = s[:30]
>
> It would translate directly to a call to PyString_FromStringAndSize(),
> which is a rather often requested feature IMO. All other base types would
> return a runtime-constructed list instead:
>
>       cdef int* x = ...
>       py_int_list = x[4:20:-1]
>
> This would generate a loop that creates Python int values from the slice
> and put them into a list, so it's basically a short form for this:
>
>       py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ]

After a little more thinking here's another perspective:

a) I support turning charptr[:length] into bytes w/ explicit length,
because I feel that's something Cython should be able to handle more
gracefully.

b) However I'm really doubting the extension to other types than char*.
It's going to be a different case (bytes and a list or array or memoryview
are very different types), and: Python is not Perl!! That is: The Python
philosophy has always been that a few characters extra to express
something is preferable to having too many concepts to learn in the
language.

I feel intptr[a:b:c] contradict this: It is a feature which it probably
takes longer to learn about than to write the perfectly good list
comprehension manually, and Python is well known to not add syntax candy
in such cases. Therefore I don't think Cython should either.

Dag Sverre



_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to