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">&lt;<a href="mailto:dalcinl@gmail.com">dalcinl@gmail.com</a>&gt;</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 &lt;<a href="mailto:sccolbert@gmail.com">sccolbert@gmail.com</a>&gt; wrote:<br>
&gt; you have to declare the attribute as public.<br>
&gt;<br>
&gt; <a href="http://docs.cython.org/docs/extension_types.html" target="_blank">http://docs.cython.org/docs/extension_types.html</a><br>
&gt;<br>
&gt; Cheers,<br>
&gt;<br>
&gt; Chris<br>
&gt;<br>
&gt; On Tue, Jun 2, 2009 at 11:17 AM, Juha Salo &lt;<a href="http://jusa.sj" target="_blank">jusa.sj</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Unfortunately that didn&#39;t seem to work. I got the following error after<br>
&gt;&gt; the change:<br>
&gt;&gt; &gt;&gt;&gt; a = Foo()<br>
&gt;&gt; Traceback (most recent call last):<br>
&gt;&gt;   File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>
&gt;&gt;   File &quot;foo.pyx&quot;, line 7, in foo.Foo.__cinit__ (foo.c:388)<br>
&gt;&gt;     self.count += 1<br>
&gt;&gt; AttributeError: &#39;foo.Foo&#39; object attribute &#39;count&#39; is read-only<br>
&gt;&gt;<br>
&gt;&gt; To clarify, I want the value of the count variable to remain the same<br>
&gt;&gt; between all instances. So if I create 3 Foo objects, each object should show<br>
&gt;&gt; 3 as the value in the count variable.<br>
&gt;&gt;<br>
&gt;&gt; 2009/6/2 Cristi Constantin &lt;<a href="mailto:darkgl0w@yahoo.com">darkgl0w@yahoo.com</a>&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Good day.<br>
&gt;&gt;&gt; You should try self.count += 1 instead of Foo.count += 1.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Cython-dev mailing list<br>
&gt;&gt; <a href="mailto:Cython-dev@codespeak.net">Cython-dev@codespeak.net</a><br>
&gt;&gt; <a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Cython-dev mailing list<br>
&gt; <a href="mailto:Cython-dev@codespeak.net">Cython-dev@codespeak.net</a><br>
&gt; <a href="http://codespeak.net/mailman/listinfo/cython-dev" target="_blank">http://codespeak.net/mailman/listinfo/cython-dev</a><br>
&gt;<br>
&gt;<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>