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


Groups > comp.lang.python > #71819

Re: Loading modules from files through C++

References (8 earlier) <53778E22.3040701@rptd.ch> <ll84s5$5bd$1@ger.gmane.org> <53790CCF.1070905@rptd.ch> <CAPTjJmrOeSsmoxqk8iCL2tKEX9Qa1yHBLzfbfvNr_7Ap+AP6pg@mail.gmail.com> <537B8E31.7000607@rptd.ch>
Date 2014-05-21 03:55 +1000
Subject Re: Loading modules from files through C++
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.10164.1400608567.18130.python-list@python.org> (permalink)

Show all headers | View raw


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.

> Furthermore I had to call the string runner with moduleDict both as
> global and local dictionary. With that change the virtual script is
> properly loaded and working as it should.

This part does make sense, though. Normally, module-level code runs
with the same locals and globals:

>>> locals() is globals()
True

And that doesn't change in Py3, so I would expect that your C++ code
also won't change.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Loading modules from files through C++ Chris Angelico <rosuav@gmail.com> - 2014-05-21 03:55 +1000

csiph-web