Extention String returning

Fredrik Lundh fredrik at pythonware.com
Mon Oct 24 14:51:32 EDT 2005


"Tuvas" wrote:

> I have been writing a program that is designed to return an 8 byte
> string from C to Python. Occasionally one or more of these bytes will
> be null, but the size of it will always be known. How can I write an
> extention module that will return the correct bytes, and not just until
> the null? I would think there would be a fairly  easy way to do this,
> but, well... Thanks!

    return PyString_FromStringAndSize(buffer, bytes);

or

    return Py_BuildValue("s#", buffer, bytes);

</F>






More information about the Python-list mailing list