No, that will not work. AFAIK, Class attributes are not currently
supported for cdef classes.

Juha, you will have to code like this:


# foo.pyx

cdef int Foo_count = 0

cdef class Foo:

    def __cinit__(self):
        global Foo_count
        Foo_count += 1




On Tue, Jun 2, 2009 at 1:36 PM, Chris Colbert <[email protected]> wrote:
> you have to declare the attribute as public.
>
> http://docs.cython.org/docs/extension_types.html
>
> Cheers,
>
> Chris
>
> On Tue, Jun 2, 2009 at 11:17 AM, Juha Salo <[email protected]> wrote:
>>
>> Unfortunately that didn't seem to work. I got the following error after
>> the change:
>> >>> a = Foo()
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "foo.pyx", line 7, in foo.Foo.__cinit__ (foo.c:388)
>>     self.count += 1
>> AttributeError: 'foo.Foo' object attribute 'count' is read-only
>>
>> To clarify, I want the value of the count variable to remain the same
>> between all instances. So if I create 3 Foo objects, each object should show
>> 3 as the value in the count variable.
>>
>> 2009/6/2 Cristi Constantin <[email protected]>
>>>
>>> Good day.
>>> You should try self.count += 1 instead of Foo.count += 1.
>>
>>
>> _______________________________________________
>> Cython-dev mailing list
>> [email protected]
>> http://codespeak.net/mailman/listinfo/cython-dev
>>
>
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to