Hi, <div><br></div><div>I got a simple problem regarding so called class variables in Cython. I'm trying to declare a simple counter as a class variable which is shared between all instances of that class. The counter'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>>>> a = Foo()</div><div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div><div> File "foo.pyx", line 7, in foo.Foo.__cinit__ (foo.c:388)</div>
<div> Foo.count += 1</div><div>TypeError: can't set attributes of built-in/extension type 'foo.Foo'</div><div><br></div><div><br></div><div>Is there a way to declare an integer class variable in Cython?</div>
</div></div>