PYTHON API : add new classes in a module from an other module

mathieu gontier mg.mailing-list at laposte.net
Tue Aug 31 13:59:48 EDT 2004


Hi every body

I am tring to create new Python modules.

In a first time, I have created a module named FOO in which I have 
inserted new classes. No problem :

    PyMODINIT_FUNC initFOO( void )
    {
          PyObject* module  = Py_InitModule3( "FOO", 0, "foo module" ) ;
          if ( ! module ) return ;

          if ( PyType_Ready( &my_type) < 0 ) return ;
          Py_INCREF( &my_type );
          PyModule_AddObject( module, "my_pytype", (PyObject*) &my_type ) ;
    }

In a second time, I would like create a new module named BAR. In the 
'init' function of this module, Ii would like add new classes in FOO.
So, I would like white something like the following :

    PyMODINIT_FUNC initBAR( void )
    {
          foo_module = Py_GetModule( "FOO" ) ;
          if( ! foo_module ) return ;

          if ( PyType_Ready( &my_addtype) < 0 ) return ;
          Py_INCREF( &my_addtype );
          PyModule_AddObject( foo_module, "my_pyaddtype", (PyObject*) 
&my_addtype ) ;
    }         

So, my question is : does it exist in the Python API, a equivalent 
function of  "Py_GetModule( <module name> )" (that a have invented for 
the example !)  ;
or does an other solution exist in order to do the same think ?

Thanks,
Mathieu 




More information about the Python-list mailing list