[Cython] [cython-users] Conditional import in pure Python mode

Stefan Behnel stefan_ml at behnel.de
Tue May 1 11:21:12 CEST 2012


>>> On 29 April 2012 01:33, Ian Bell wrote:
>>>> idiom like
>>>>
>>>> if cython.compiled:
>>>>     cython.import('from libc.math cimport sin')
>>>> else:
>>>>     from math import sin

Actually, in this particular case, I would even accept a solution that
special cases the "math" module internally by automatically cimporting
libc.math as an override (or rather an adapted version as plain "math.pxd").

This CEP describes a general approach:

http://wiki.cython.org/enhancements/overlaypythonmodules

It's partly outdated, so things may have become easier these days.

Stefan


More information about the cython-devel mailing list