Skip to content

Instantly share code, notes, and snippets.

@arekt
Last active May 15, 2020
Embed
What would you like to do?
```
## based on: https://docs.python.org/2/extending/embedding.html
arek@qyobo:~/workspace/embeding_python$ gcc -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 main.c -lpython2.7 -o run-python
arek@qyobo:~/workspace/embeding_python$ cat main.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");
PyRun_SimpleString(argv[1]);
Py_Finalize();
return 0;
}
arek@qyobo:~/workspace/embeding_python$ ./run-python "print ctime(time())"
Fri May 15 19:14:11 2020
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment