C API and memory allocation
Stefan Behnel
stefan_ml at behnel.de
Fri Dec 19 04:46:22 EST 2008
Aaron Brady wrote:
>>> Otherwise you can't know its length or change its reference count.
>> The internal representation of Python byte strings is 0 terminated, so
>> strlen() will work.
>
> As MRAB said, Python strings can contain null bytes,
Sure, they can. Most byte strings I've seen didn't, though. And if you know
that they don't contain any null bytes (UTF-8 serialised XML, for example,
or ASCII encoded text, or ...), 's' is just fine. If you need content *and*
length, use 's#'. Matter of use case, as usual.
Stefan
More information about the Python-list
mailing list