from math import sqrt
defprimes(n:int):"""
primes(n: int=2) -> list
求质数
:param n: n
:return: 返回列表
"""
cdef int i, j
results =[1,]for i inrange(2, n):for j inrange(2,int(sqrt(i))):if i % j ==0:breakelse:
results.append(i)return results
./cal/init.py
from.cal import primes
编写编译脚本setup.py
from distutils.core import setup, Extension
from Cython.Build import cythonize
setup(
name='cal',
version='1.0',
ext_modules=cythonize(["./cal/*.pyx"]),
package_data={'cal':["*.so"]},
packages=['cal','cal'],)