[Cython] Defaults in cdef or cpdef methods

Robert Bradshaw robertwb at math.washington.edu
Thu Jun 19 20:09:25 CEST 2008


On Jun 19, 2008, at 5:07 AM, Johannes Wienke wrote:

> Hi,
>
> is there a was to use default values for parameters in cdef or cpdef
> methods? I observed that using them in the pxd files caused a cython
> compiler error and using the only in the implementation causes a C
> compiler error.

Yes, you need to declare them to have default parameters in .pxd  
files, then can use them in .pyx files. For example:

---- pxd ----

cdef foo(x, y=*)

---- pyx ----

cdef foo(x, y=None):
     print x,y

See http://wiki.cython.org/DifferencesFromPyrex#head- 
b2cbb6bf07c3c8c5bb0d10b89d9736eb0fc63440

- Robert

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://codespeak.net/pipermail/cython-dev/attachments/20080619/cb4908d2/attachment.pgp 


More information about the Cython-dev mailing list