python 生成 pyd 隐藏python 代码

# Calculate.py

class Calculate:

    def add(self, x, y):
        return x + y

# setup.py

from setuptools import setup
from Cython.Build import cythonize

setup(
    name="demo",
    ext_modules=cythonize("Calculate.py")
)

python setup.py install

import demo

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    calculate = demo.Calculate()
    ret = calculate.add(11, 111)
    print(ret)
posted @ 2025-04-18 09:42  dilex  阅读(19)  评论(0)    收藏  举报