Q:

Cython and arrays

I am trying to Cython to speed up some class. But I still want the code to run in pure Python too.
How do I define an array in an class (code has been simplified)
import cython

class A:
    def __init__(self):

        if cython.compiled:

            # This will work in Cython
            for k in len(self.S):
               self.S[k]=k

        else:
            # This will work in interpreter
            self.S=range(8)

    def test(self):
         self.S[0]+=1

And in the .pxd:
 import cython

 cdef class A
     cdef int[8] S

     cdef test(self)

But Cython complains on compilation:
Cannot convert Python object to 'int [8]'

A:

I finally got it to work:
import array

class A:
    def __init__(self):

        # This will work in Cython
        self.S=array.array("l", range(8))

    def test(self):
         self.S[0]+=1

And .pxd:
cimport cpython.array

cdef class RC4:
    cdef int [:] S
    cdef int test(self)

