[Pyrex] New to Pyrex: how to I make strings as attributes?

Greg Ewing greg at cosc.canterbury.ac.nz
Mon Nov 1 01:14:27 CET 2004


Lennart Regebro wrote:
> 
> how do I get that pesky char szPname[32] into 
> a python accessible string attribute?

If it were directly an attribute of the extension type, you'd
be able to declare it 'public', but since it's nested inside a
struct, you can't do that.

You could use a property. Something like (warning, untested):

   cdef class outPort:

     property szPname:

       def __get__(self):
         return self.mic.szPname

       def __set__(self, char *s):
         strncpy(self.mic.szPname, s, 32)

--
Greg





More information about the Pyrex mailing list