[Cython] Defaults in cdef or cpdef methods

Robert Bradshaw robertwb at math.washington.edu
Thu Jun 19 20:28:45 CEST 2008


On Jun 19, 2008, at 11:23 AM, Johannes Wienke wrote:

> Am 06/19/2008 08:09 PM schrieb Robert Bradshaw:
>> On Jun 19, 2008, at 5:07 AM, Johannes Wienke wrote:
>>> 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=*)
>
> The compiler told me to use '?'. Is that a "bug" in the error message?

No, both are acceptable.

>
>> ---- pyx ----
>>
>> cdef foo(x, y=None):
>>     print x,y
>>
>> See
>> http://wiki.cython.org/DifferencesFromPyrex#head- 
>> b2cbb6bf07c3c8c5bb0d10b89d9736eb0fc63440
>
> Thanks for the help!
> Johannes
>
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev

-------------- 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/7c25351f/attachment-0001.pgp 


More information about the Cython-dev mailing list