Hi, <div><br></div><div>I got a simple problem regarding so called class variables in Cython. I&#39;m trying to declare a simple counter as a class variable which is shared between all instances of that class. The counter&#39;s value should be incremented as instances of the class are created. Cython allows me to declare a Python dictionary as a class variable, but the following gives me an error:</div>
<div><br></div><div><br></div><div># foo.pyx</div><div><br></div><div><div>cdef class Foo:</div><div>    count = 0</div><div><br></div><div>    def __cinit__(self):</div><div>        Foo.count += 1</div><div><br></div><div>
<br></div><div><div>&gt;&gt;&gt; a = Foo()</div><div>Traceback (most recent call last):</div><div>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;</div><div>  File &quot;foo.pyx&quot;, line 7, in foo.Foo.__cinit__ (foo.c:388)</div>
<div>    Foo.count += 1</div><div>TypeError: can&#39;t set attributes of built-in/extension type &#39;foo.Foo&#39;</div><div><br></div><div><br></div><div>Is there a way to declare an integer class variable in Cython?</div>
</div></div>