adding new function

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Jun 23 03:20:50 EDT 2010


En Tue, 22 Jun 2010 14:18:59 -0300, Terry Reedy <tjreedy at 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




More information about the Python-list mailing list