OK, thanks for the info. It's interesting, though, that I can code something
like this in Cython and it works:

cdef class Foo:
    foos = {}

    def __cinit__(self, name):
        Foo.foos[name] = self


>>> a = Foo('Larry')
>>> b = Foo('Bob')
>>> a.foos
{'Bob': <foo.Foo object at 0x01C5F490>, 'Larry': <foo.Foo object at
0x01C5F488>}
>>> b.foos
{'Bob': <foo.Foo object at 0x01C5F490>, 'Larry': <foo.Foo object at
0x01C5F488>}


Perhaps I could use a hack workaround with the aforementioned count variable
by storing it inside a class level list object.


2009/6/2 Chris Colbert <sccolb...@gmail.com>

> This is correct, forget what I said. I should have tried it out before I
> said anything. My apologies.
>
>
>
> On Tue, Jun 2, 2009 at 12:44 PM, Lisandro Dalcin <dalc...@gmail.com>wrote:
>
>> 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 <sccolb...@gmail.com>
>> 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 <jusa...@gmail.com> 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 <darkg...@yahoo.com>
>> >>>
>> >>> Good day.
>> >>> You should try self.count += 1 instead of Foo.count += 1.
>> >>
>> >>
>> >> _______________________________________________
>> >> Cython-dev mailing list
>> >> Cython-dev@codespeak.net
>> >> http://codespeak.net/mailman/listinfo/cython-dev
>> >>
>> >
>> >
>> > _______________________________________________
>> > Cython-dev mailing list
>> > Cython-dev@codespeak.net
>> > 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
>> Cython-dev@codespeak.net
>> http://codespeak.net/mailman/listinfo/cython-dev
>>
>
>
> _______________________________________________
> Cython-dev mailing list
> Cython-dev@codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev
>
>
_______________________________________________
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to