On 05/20/2014 07:55 PM, Chris Angelico wrote:
> On Wed, May 21, 2014 at 3:17 AM, Roland Plüss <rol...@rptd.ch> wrote:
>> The important part are the last two lines. An important module is
>> lacking the __builtins__ dictionary member so I had to add it.
>> Hopefully this works also in Py3 should I switch some time later. But I
>> guess it should seeing how simple the import now became.
> An interesting omission, I'm a little surprised at that. But if your
> switch to Py3 is a serious (or even half-serious) possibility, I
> recommend tossing a quick comment against that line of code. Check to
> see if you actually need it, and if you still do, see if there's a
> change there. The module has been renamed (from __builtin__ to
> builtins, although the global reference to it is still __builtins__),
> so you may need to adjust something there, too. But mainly, see if you
> can drop that line of code in Py3.
That has been a huge mess. Py3 totally messes things up there. Even the
most simply code doesn't work. Take this example:

# CODE #
PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, NULL, NULL, 0, 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'

This worked in Py2 and in Py3 created modules are invisible breaking
anything. Why is there no sane documentation providing a working example
for something that elementary. Any ideas what Py3 requires that it does
not write into the docs as one should do?

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

Attachment: signature.asc
Description: OpenPGP digital signature


Reply via email to