How to Embed in Python
Python is a high level computer programming language designed by Guido van Rossum in 1991. Python is licensed through the "Python Software Foundation License," which is a free software license. You can embed the Python programming language into other programming languages such as C and C++. With the use of specific header files, you can implement syntax into a C project that will allow you to embed Python into your project. Windows Notepad can be used to perform this operation.
Instructions
-
-
1
Visit the official Python website at python.org and download the "Python.h" header file. Save the file to the folder in which your C programming project exists.
-
2
Locate the C programming file in which you want to implement Python code. Right-click on the file, click on "Open with," then click on "Notepad." The C file will open in Windows Notepad.
-
-
3
At the top of the program, copy and paste the following syntax:
#include <Python.h>
This will include the Python header file.
-
4
Implement the following syntax into the program, directly after the final header file inclusion:
int main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;
}
This is an example of high level embedding in a C-based program.
-
5
Press "Ctrl" and "S" on your keyboard to save the file. Exit Notepad.
-
1