September 2018
Intermediate to advanced
606 pages
14h 32m
English
We will use a simple example of Python embedding into a C program that can be found on the Python documentation pages. The source file is called hello-embedded-python.c:
#include <Python.h> int main(int argc, char *argv[]) { Py_SetProgramName(argv[0]); /* optional but recommended */ Py_Initialize(); PyRun_SimpleString("from time import time,ctime\n" "print 'Today is',ctime(time())\n"); Py_Finalize(); return 0;}
This code samples will initialize an instance of the Python interpreter within the program and print the date using the time Python module.
Read now
Unlock full access