From: Daniel Fetchinson on 22 Jun 2010 05:44 > how can i simply add new functions to module after its initialization > (Py_InitModule())? I'm missing something like > PyModule_AddCFunction(). This type of question really belongs to python-list aka comp.lang.python which I CC-d now. Please keep the discussion on that list. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown
From: Terry Reedy on 22 Jun 2010 13:18 On 6/22/2010 5:44 AM, Daniel Fetchinson wrote: >> how can i simply add new functions to module after its initialization >> (Py_InitModule())? I'm missing something like >> PyModule_AddCFunction(). in Python, for modules written in python import mymod mymod.fname = somefunc #or setattr(mymod, namestring, funcobject) I presume you use the C-API equivalent of setattr. -- Terry Jan Reedy
From: Gabriel Genellina on 23 Jun 2010 03:20 En Tue, 22 Jun 2010 14:18:59 -0300, Terry Reedy <tjreedy(a)udel.edu> escribi�: > On 6/22/2010 5:44 AM, Daniel Fetchinson wrote: >>> how can i simply add new functions to module after its initialization >>> (Py_InitModule())? I'm missing something like >>> PyModule_AddCFunction(). > > in Python, for modules written in python > > import mymod > mymod.fname = somefunc #or > setattr(mymod, namestring, funcobject) > > > I presume you use the C-API equivalent of setattr. That one, or PyModule_AddObject (just for nicer error messages really). -- Gabriel Genellina
From: Christian Heimes on 23 Jun 2010 04:22 Am 22.06.2010 19:18, schrieb Terry Reedy: > On 6/22/2010 5:44 AM, Daniel Fetchinson wrote: >>> how can i simply add new functions to module after its initialization >>> (Py_InitModule())? I'm missing something like >>> PyModule_AddCFunction(). > > in Python, for modules written in python > > import mymod > mymod.fname = somefunc #or > setattr(mymod, namestring, funcobject) For C code, it's a more complex. You have to construct a proper C function PyObject* from a PyMethodDef* first. See Python/modsupport.c:Py_InitModule4(). Christian
|
Pages: 1 Prev: Should I Learn Python or Ruby next? Next: From Dict to Classes yes or no and how |