본문 바로가기
Python/0x05-ctypes

c에서 python 호출하기 ][ test

by SpeeDr00t 2019. 9. 27.
반응형

c에서 python 호출하기 ][ test

■ 사용법

/*
test by kyoung chip , jang
sudo apt-get install python-dev
sudo apt-get install python3-dev
gcc -o p1 p1.c -I/usr/include/python2.7 -lpython2.7
*/
#include <Python.h>
int main( void )
{
Py_Initialize();
PyRun_SimpleString("import sys; sys.path.append('.')");
PyRun_SimpleString("import callme;");
PyRun_SimpleString("print( callme.test(\"test\") ) ");
Py_Finalize();
return 0;
}
view raw p1.c hosted with ❤ by GitHub
#
# test by kyoung chip , jang
#
def test( data ) :
return( "receive = %s " % data )
view raw callme.py hosted with ❤ by GitHub

반응형

'Python > 0x05-ctypes' 카테고리의 다른 글

ctypes class ][ python에서 c++ class 사용하기  (0) 2017.10.08