Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71871 > unrolled thread

Re: Loading modules from files through C++

Started byRoland Plüss <roland@rptd.ch>
First post2014-05-22 00:09 +0200
Last post2014-05-22 00:09 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Loading modules from files through C++ Roland Plüss <roland@rptd.ch> - 2014-05-22 00:09 +0200

#71871 — Re: Loading modules from files through C++

FromRoland Plüss <roland@rptd.ch>
Date2014-05-22 00:09 +0200
SubjectRe: Loading modules from files through C++
Message-ID<mailman.10207.1400710205.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On 05/20/2014 07:55 PM, Chris Angelico wrote:
> On Wed, May 21, 2014 at 3:17 AM, Roland Plüss <roland@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,
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'

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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web