title: How do I build a python string from a ctype struct?
body: <p>I'm using ctypes and I've defined this struct in order to pass parameters</p>
  
  <pre><code>class my_struct(ctypes.Structure):
      _fields_ = [ ("buffer", ctypes.c_char * BUFSIZE),
                   ("size", ctypes.c_int )]
  </code></pre>
  
  <p>Then I call the C function using the following code, but I don't know how to create a string from the struct I've created.</p>
  
  <pre><code>class Client():
  
      def __init__(self):
          self.__proto = my_struct()
          self.client = ctypes.cdll.LoadLibrary(r"I:\bin\client.dll")
  
      def version(self):
          ret = self.client.execute(ctypes.byref(self.__proto))
          my_string = self.__proto.buffer[:self.__proto.size]
  </code></pre>
  
  <p>I want to create a python string using the first n bytes of the buffer (the buffer contains NULL characters but I have to handle this situation and create the string with /0x00 characters if necesary). The asignation </p>
  
  <pre><code>my_string = self.__proto.buffer[:self.__proto.size]
  </code></pre>
  
  <p>is not working bacause truncates the string if 0x00 appears. Any idea is welcome. Thanks in advance.</p>