Re: ctypes char array question
Steve Thompson <[email protected]> Thu, 1 Dec 2011 15:16:43 -0600
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <CAKPZRnUtstBoYVqaN8YSpCU4gpdiov98hgoGUxP8FURJS-0yRg@mail.gmail.com> |
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.
Thanks,
Steve
------------------------------------------------------------------------------
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
_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users