Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion __init__ not creating python variables.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Robert Bradshaw  
View profile  
 More options Nov 13 2012, 1:21 pm
From: Robert Bradshaw <rober...@gmail.com>
Date: Tue, 13 Nov 2012 10:20:44 -0800
Local: Tues, Nov 13 2012 1:20 pm
Subject: Re: [cython-users] __init__ not creating python variables.

On Tue, Nov 13, 2012 at 10:13 AM, RC <ravi...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.