Hi,
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:


# foo.pyx

cdef class Foo:
    count = 0

    def __cinit__(self):
        Foo.count += 1


>>> 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)
    Foo.count += 1
TypeError: can't set attributes of built-in/extension type 'foo.Foo'


Is there a way to declare an integer class variable in Cython?
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to