On Tue, Nov 13, 2012 at 10:13 AM, RC <
rav...@gmail.com> wrote:
> In the following example, i am facing an issue in initializing python object
> variables:
>
> cdef extern from "X.h" namespace "xxx":
> cdef cppclass X:
> char* create(char*)
> void update(char*)
>
> cdef class PyX:
> cdef X* xPtr
> def __cinit__(self):
> xPtr = ....
>
> def __init__(self):
> self.created = False
>
> def create(self, name):
> ptr = self.xPtr.create(name)
> self.created = True
> return ptr
>
> def update(self, name):
> if self.created:
> self.xPtr.update(name)
> return True
> return False
>
> It compiles fine but when i create an instance of X it complains:
> AttributeError: 'X' object has no attribute 'created'
>
> Any ideas on how to work around this is appreciated.
All members of cdef functions must be explicitly declared. Write
cdef class PyX:
cdef X* xPtr
cdef object created
...
(Might as well make "created" a public bint, no need to let it be a
Python object if it's going to be True/False.)
- Robert