[Cython] Lists?

Stefan Behnel stefan_ml at behnel.de
Mon Sep 1 21:13:11 CEST 2008


Hi,

Hoyt Koepke wrote:
> One of my main questions when I initially thought about it is how to
> handle the operator methods in c++.  When I define __getitem__, I have
> to define it as a python function using def, so is it compiled
> directly into c code? To ask it another way, is there any way to
> create a class A such that I can write
> 
> a = A(...)
> a[i] += 1
> 
> and have the a[i] += 1 be entirely c(++) code?

Yes, but within the limits of the Python getitem protocol. This means that the
item itself will be a Python object, and thus the "+= 1" will be executed on
two Python objects.

Stefan


More information about the Cython-dev mailing list