[ZODB-Dev] embedded null bytes in python strings?

Phillip J. Eby pje@telecommunity.com
Thu, 10 Apr 2003 13:45:22 -0400


At 10:33 AM 4/10/03 -0700, rys mccusker wrote:
>can python strings contain bytes equal to 0x00?

Yes.


>I.e. can strings contain arbitrary binary data?
>
>I ask here because I thought it might take awhile to find
>the answer in an online search for a minor issue.
>
>on a related note, perhaps automated python interface
>generation using SWIG is most friendly to C style strings
>with null termination.  is there a SWIG approach which
>favors binary data and strings?

I don't know about that, but I do know that I vastly prefer Pyrex to SWIG 
for creating Python-to-C interfaces.  Pyrex is basically Python code with 
the ability to declare and use C variable and function types.  You write 
some very Python-like code, run it through Pyrex, and get C source 
code.  The resulting interface is *much* more Pythonic than what you can 
get in SWIG without extensive typemapping work.  See:

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

for information on Pyrex.