Extention String returning

T

Tuvas

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!
 
J

jepler

I think that you want to use
return PyString_FromStringAndSize(buf, 8);

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDXSwxJd01MZaTXX0RAraIAJ9IZ+pa8oWUC3HTKkKG3ihHoiw5ZACdGqzP
9EietMnOAAsfWkS3SzzA4l4=
=QTYP
-----END PGP SIGNATURE-----
 
F

Fredrik Lundh

Tuvas said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top