Pythonのお勉強 Part 27at TECH
Pythonのお勉強 Part 27 - 暇つぶし2ch394:デフォルトの名無しさん
08/07/01 09:12:00
>>392
#include <Python.h> //--- Python API ヘッダの指定
// Python.h には既に stdio.h string.h errno.h stdlib.h のインクルード指定が含まれています

// メソッドの実体
static PyObject* exec_do(PyObject* self, PyObject* args)
{
const char* command ; //--- command は PyArg_ParseTuple によって alloc される
int status ;

if (!PyArg_ParseTuple(args, "s", &command))
return NULL ;
status = system(command) ;

return Py_BuildValue("i", status) ;
}

// メソッドテーブル
// メソッド名 / 関数へのポインタ / 呼び出し規則 / 説明書き(何を書いても良い)
// python の help から参照することができます。
static PyMethodDef executerMethods [] = {
{ "do", exec_do, METH_VARARGS, "Execute command for Command-prompt in Windows." },
{ NULL, NULL, 0, NULL }
};

// モジュールの初期化関数 (Python にモジュール名とメソッドテーブルを渡します)
PyMODINIT_FUNC initexecuter(void) // 初期化モジュール名は init + "DLL 名" にする必要があります。
{
Py_InitModule("executer", executerMethods) ; // モジュール名は DLL 名と同じにする必要があります。
}

dll -> pyd(2.5で変更) だからPython C APIで拡張を書いてあげればpython側で認識してくれると思われ


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch