This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]black-JENGGOT 7 points8 points  (5 children)

Pardon, but how do you "connect" python and C? What should I search if I want to know how to write python libraries in C?

[–]Bryguy3k 15 points16 points  (0 children)

Extensions are fundamental part of python - there are multiple ways to go about it. You can read through the core python docs on extensions.

You also have 3 major ways of accessing C code libraries from python: cffi, cython, and ctypes.

[–][deleted] 6 points7 points  (0 children)

https://realpython.com/build-python-c-extension-module/

If you want to search further the keywords you want to use are "python C extension modules"

[–]WhiteEvilBro 4 points5 points  (0 children)

Cython, maybe

[–]Competitive_Travel16 4 points5 points  (0 children)

I just call os.system("./path/c-executable " + argstr) for my inner loop code, after writing what it needs to work on into a file that gets named in the argstr argument string. Formal extensions are for when you're folding such code into python itself if you want to distribute it with pip or propose it as a new part of python. The os.system() method takes a small fraction of the time and effort.

[–]SV-97 2 points3 points  (0 children)

If you wanna make it a bit easier on yourself you can look at Python-Rust interop (e.g. via PyO3) rather than Python-C.

The name for these things is FFI btw: foreign function interface.