When C calls the Python module to initialize the Python interpreter, import modules, etc., but Python calls the C module is relatively simple, the following is a description of HELLOWORLD.C and main.py:
(1) Write C code, HELLO.C code is simple, just output "Hello world! ": (2) Compile the C code into the form of a dynamic link library, specific commands: in this case, the libhello.so dynamic link library is generated in the current directory: (3) Import the dynamic link library in main.py and call the C functionhere ctypes is an external library of Python, providing the C language compatible data types to facilitate the call C compiled static libraries and functions in the dynamic library, it can be sure that the ctypes in the C data type is converted, using only import cTYPES, then import the dynamic library. (4) Enter Python main.py under terminal to run the result: Print out the contents of the HELLOWORLD.C, stating that Python calls C module successfully!
Linux under Python calls C module