[Python-ideas] Why don't CPython strings implement slicing using a view?

Chris Angelico rosuav at gmail.com
Fri May 8 04:02:01 CEST 2015


On Fri, May 8, 2015 at 11:54 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, May 07, 2015 at 03:12:58PM -0500, Skip Montanaro wrote:
>> I haven't seen anyone else mention it, so I will point out:
>> interoperability with C. In C, strings are NUL-terminated. PyStringObject
>> instances do (or used to) have NUL-terminated strings in them. According to
>> unicodeobject.h, that seems still to be the case:
>
> How does that work? Python strings can contain embedded NULs:
>
> s = u"abc\0def"

It's a pure convenience. It means that C string operations are
guaranteed to terminate; they aren't guaranteed to process the whole
string, but they won't run on into random memory. For a lot of cases,
that's pretty handy.

ChrisA


More information about the Python-ideas mailing list