Last active
May 15, 2020 10:17
-
-
Save arekt/7f846d45fcf5283ebcdc51b318130344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
## 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