2009/5/18 Juha Salo <[email protected]>:
> Hi,
> I ran into a rather basic problem where I can't seem to change the value of
> a module-level Cython variable through a cpdef'd Cython function. I have the
> following:
> #foo.pyx
> cdef float foovar = 0.001
> cpdef float get_foo():
>     return foovar
> cpdef set_foo(float v=0.001):
>     foovar = v

Maybe you are modifing a local variable foovar in set_foo function.
Try to use global scope or encapsulate all in a class.

>
>
> When I call get_foo() at the Python interpreter I get the value 0.001, but
> trying to change foovar's value with set_foo() has no effect. I also tried
> to cpdef foovar but that didn't help. I could probably (?) define foovar as
> a regular Python variable, but I'd rather have it as a Cython variable for
> speed. Is there anything special that needs to be done to get this to work?
> Thanks,
> J.S.
> _______________________________________________
> 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

Reply via email to