This is correct, forget what I said. I should have tried it out before I said anything. My apologies. <br><br><br><br><div class="gmail_quote">On Tue, Jun 2, 2009 at 12:44 PM, Lisandro Dalcin <span dir="ltr"><<a href="mailto:dalcinl@gmail.com">dalcinl@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">No, that will not work. AFAIK, Class attributes are not currently<br>
supported for cdef classes.<br>
<br>
Juha, you will have to code like this:<br>
<br>
<br>
# foo.pyx<br>
<br>
cdef int Foo_count = 0<br>
<br>
cdef class Foo:<br>
<br>
def __cinit__(self):<br>
global Foo_count<br>
Foo_count += 1<br>
<div><div></div><div class="h5"><br>
<br>
<br>
<br>
On Tue, Jun 2, 2009 at 1:36 PM, Chris Colbert <<a href="mailto:sccolbert@gmail.com">sccolbert@gmail.com</a>> wrote:<br>
> you have to declare the attribute as public.<br>
><br>
> <a href="http://docs.cython.org/docs/extension_types.html" target="_blank">http://docs.cython.org/docs/extension_types.html</a><br>
><br>
> Cheers,<br>
><br>
> Chris<br>
><br>
> On Tue, Jun 2, 2009 at 11:17 AM, Juha Salo <<a href="http://jusa.sj" target="_blank">jusa.sj</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>> wrote:<br>
>><br>
>> Unfortunately that didn't seem to work. I got the following error after<br>
>> the change:<br>
>> >>> a = Foo()<br>
>> Traceback (most recent call last):<br>
>> File "<stdin>", line 1, in <module><br>
>> File "foo.pyx", line 7, in foo.Foo.__cinit__ (foo.c:388)<br>
>> self.count += 1<br>
>> AttributeError: 'foo.Foo' object attribute 'count' is read-only<br>
>><br>
>> To clarify, I want the value of the count variable to remain the same<br>
>> between all instances. So if I create 3 Foo objects, each object should show<br>
>> 3 as the value in the count variable.<br>
>><br>
>> 2009/6/2 Cristi Constantin <<a href="mailto:darkgl0w@yahoo.com">darkgl0w@yahoo.com</a>><br>
>>><br>
>>> Good day.<br>
>>> You should try self.count += 1 instead of Foo.count += 1.<br>
>><br>
>><br>
>> _______________________________________________<br>
>> Cython-dev mailing list<br>
>> <a href="mailto:Cython-dev@codespeak.net">Cython-dev@codespeak.net</a><br>
>> <a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> Cython-dev mailing list<br>
> <a href="mailto:Cython-dev@codespeak.net">Cython-dev@codespeak.net</a><br>
> <a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
><br>
><br>
<br>
<br>
<br>
</div></div><font color="#888888">--<br>
Lisandro Dalcín<br>
---------------<br>
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)<br>
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)<br>
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)<br>
PTLC - Güemes 3450, (3000) Santa Fe, Argentina<br>
Tel/Fax: +54-(0)342-451.1594<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Cython-dev mailing list<br>
<a href="mailto:Cython-dev@codespeak.net">Cython-dev@codespeak.net</a><br>
<a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
</div></div></blockquote></div><br>