Loading modules from files through C++

Roland Plüss roland at rptd.ch
Sat May 24 10:48:23 EDT 2014


> # CODE #
> PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, NULL, NULL, 0, NULL,
> NULL, NULL, NULL, NULL };
>
> moduledef.m_name = "MyModule";
> moduledef.m_doc = "MyModule";
> pModule = PyModule_Create( &moduledef );
> PyState_AddModule( pModule, &moduledef );
>
> PyRun_SimpleString( "print( globals() )\n" );
> PyRun_SimpleString( "import MyModule\nprint( globals() )\n" );
> # CODE #
>
> yields this:
>
> {'__name__': '__main__', '__builtins__': <module 'builtins' (built-in)>,
> '__doc__': None, '__loader__': <class
> '_frozen_importlib.BuiltinImporter'>, '__package__': None}
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
> ImportError: No module named 'MyModule'
>
Anybody got an idea? Somebody has a working example where he create a
valid module from C++? It's just a namespace not even yet script sources
applied.

-- 
Yours sincerely
Plüss Roland

Leader and Head Programmer
- Game: Epsylon ( http://www.indiedb.com/games/epsylon )
- Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine
, http://dragengine.rptd.ch/wiki )
- Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php )
- As well as various Blender export scripts und game tools

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20140524/c6ec8218/attachment.sig>


More information about the Python-list mailing list