Re: ctypes char array question

Thomas Heller <[email protected]> Fri, 02 Dec 2011 18:09:17 +0100
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Am 01.12.2011 22:16, schrieb Steve Thompson:
>      Assume:
>          import ctypes
>          class str_type(ctypes.Array):
>              _type_ = ctypes.c_char
>              _length_ = 4
>          class struct(ctypes.Structure):
>              _fields_ = ( ("first", str_type),
>                           ("second", ctypes.c_int), )
>          x = struct()
>          x.first = "a\0bc"
>          print "x.first:", x.first, x.second
>
> The output is “x.first: a 0”.Is there a way to access the part of the
> array that’s after the null terminator like you would be able to in
> normal C code?  I’ve inspected the type and don’t really see a way to do
> this.  As a temporary work around I’ve changed it to an array of uint8.

Your workaround is fine.  There doesn't seem to be another way.

Thomas


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d