How can I create a language independent library using Python?

后端 未结 7 1873
夕颜
夕颜 2021-01-11 10:51

If I create a package in Python, then another Python user can import that package and interface with it.

How can I create a package so that it doesn\'t matter what l

7条回答
  •  误落风尘
    2021-01-11 11:12

    You can use Cython to relatively easily extend your python code so that it can be compiled as a C library. Mostly, this just involved replacing the def keyword with cdef public for the functions you want to expose, and annotating your variables types.

    Here's an example of such Cython code:

    cdef public void grail(int num):
        printf("Ready the holy hand grenade and count to %i", num) 
    

    At that point, many languages have Foreign Function Interfaces (FFI) to C code.

提交回复
热议问题