Good day. You should try self.count += 1 instead of Foo.count += 1. --- On Tue, 6/2/09, Juha Salo <[email protected]> wrote:
From: Juha Salo <[email protected]> Subject: [Cython] Syntax for declaring Cython class variables To: [email protected] Date: Tuesday, June 2, 2009, 3:43 AM 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 += 1TypeError: can't set attributes of built-in/extension type 'foo.Foo' Is there a way to declare an integer class variable in Cython? -----Inline Attachment Follows----- _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
