Cython import function from another pyx

Two pyx files,

f1.pyx

 cpdef double func1(): return 0.01 

f2.pyx

 from f1 cimport func1 

How do I import func1 from f1.pyx ? The reason is because I have different sections and you want to put them in separate pyx files. But I could not import after I break them.

+5
source share
1 answer

When you use a function from another file with cimport , Cython needs a definition file ( *.pxd file) as well as an implementation file. (see here for the relevant section of the documentation)

If you also create a file called f1.pxd containing the following:

 cpdef double func1() 

Your example should compile.

+3
source

Source: https://habr.com/ru/post/1215711/


All Articles